Skip to content

Commit

Permalink
chore: the gitlab merge request payload is outdated
Browse files Browse the repository at this point in the history
  • Loading branch information
xNok committed Oct 10, 2023
1 parent d63b350 commit 4766a27
Showing 1 changed file with 88 additions and 104 deletions.
192 changes: 88 additions & 104 deletions gitlab/gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,23 @@ func TestBadRequests(t *testing.T) {
for _, tt := range tests {
tc := tt
client := &http.Client{}
t.Run(
tt.name, func(t *testing.T) {
t.Parallel()
var parseError error
server := newServer(
func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, tc.event)
},
)
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, tc.payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
var parseError error
server := newServer(func(w http.ResponseWriter, r *http.Request) {
_, parseError = hook.Parse(r, tc.event)
})
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, tc.payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")

resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.Error(parseError)
},
)
resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.Error(parseError)
})
}
}

Expand Down Expand Up @@ -267,36 +263,32 @@ func TestWebhooks(t *testing.T) {
for _, tt := range tests {
tc := tt
client := &http.Client{}
t.Run(
tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()

var parseError error
var results interface{}
server := newServer(
func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, tc.event)
},
)
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")
var parseError error
var results interface{}
server := newServer(func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, tc.event)
})
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")

resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
},
)
resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
})
}
}

Expand All @@ -323,36 +315,32 @@ func TestJobHooks(t *testing.T) {
for _, tt := range tests {
tc := tt
client := &http.Client{}
t.Run(
tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()

var parseError error
var results interface{}
server := newServer(
func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, tc.events...)
},
)
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")
var parseError error
var results interface{}
server := newServer(func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, tc.events...)
})
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header = tc.headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")

resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
},
)
resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
})
}
}

Expand Down Expand Up @@ -506,35 +494,31 @@ func TestSystemHooks(t *testing.T) {
for _, tt := range tests {
tc := tt
client := &http.Client{}
t.Run(
tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
payload, err := os.Open(tc.filename)
assert.NoError(err)
defer func() {
_ = payload.Close()
}()

var parseError error
var results interface{}
server := newServer(
func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, SystemHookEvents, tc.event)
},
)
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")
req.Header.Set("X-Gitlab-Event", "System Hook")
var parseError error
var results interface{}
server := newServer(func(w http.ResponseWriter, r *http.Request) {
results, parseError = hook.Parse(r, SystemHookEvents, tc.event)
})
defer server.Close()
req, err := http.NewRequest(http.MethodPost, server.URL+path, payload)
assert.NoError(err)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Gitlab-Token", "sampleToken!")
req.Header.Set("X-Gitlab-Event", "System Hook")

resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
},
)
resp, err := client.Do(req)
assert.NoError(err)
assert.Equal(http.StatusOK, resp.StatusCode)
assert.NoError(parseError)
assert.Equal(reflect.TypeOf(tc.typ), reflect.TypeOf(results))
})
}
}

0 comments on commit 4766a27

Please sign in to comment.