Commit 8666683d authored by Gabor Pipicz's avatar Gabor Pipicz

Adjust POST/PUT tests: search the body for request payload

parent 3159fab2
package gitlab
import (
"encoding/json"
"io/ioutil"
"net/http"
"net/http/httptest"
......@@ -74,6 +75,20 @@ func testBody(t *testing.T, r *http.Request, want string) {
}
}
func testJsonBody(t *testing.T, r *http.Request, want values) {
b, err := ioutil.ReadAll(r.Body)
if err != nil {
t.Errorf("Error reading request body: %v", err)
}
var got values
json.Unmarshal(b, &got)
if !reflect.DeepEqual(got, want) {
t.Errorf("Request parameters: %v, want %v", got, want)
}
}
func responseBody(w http.ResponseWriter, filename string) {
body, _ := ioutil.ReadFile(filename)
w.Write([]byte(body))
......
......@@ -177,7 +177,7 @@ func TestCreateProject(t *testing.T) {
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
testFormValues(t, r, values{
testJsonBody(t, r, values{
"name": "n",
})
......
......@@ -13,7 +13,7 @@ func TestSetDroneCIService(t *testing.T) {
mux.HandleFunc("/projects/1/services/drone-ci", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
testFormValues(t, r, values{
testJsonBody(t, r, values{
"token": "t",
"drone_url": "u",
"enable_ssl_verification": "true",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment