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

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

parent 3159fab2
package gitlab package gitlab
import ( import (
"encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
...@@ -74,6 +75,20 @@ func testBody(t *testing.T, r *http.Request, want string) { ...@@ -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) { func responseBody(w http.ResponseWriter, filename string) {
body, _ := ioutil.ReadFile(filename) body, _ := ioutil.ReadFile(filename)
w.Write([]byte(body)) w.Write([]byte(body))
......
...@@ -177,7 +177,7 @@ func TestCreateProject(t *testing.T) { ...@@ -177,7 +177,7 @@ func TestCreateProject(t *testing.T) {
mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/projects", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST") testMethod(t, r, "POST")
testFormValues(t, r, values{ testJsonBody(t, r, values{
"name": "n", "name": "n",
}) })
......
...@@ -13,7 +13,7 @@ func TestSetDroneCIService(t *testing.T) { ...@@ -13,7 +13,7 @@ func TestSetDroneCIService(t *testing.T) {
mux.HandleFunc("/projects/1/services/drone-ci", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/projects/1/services/drone-ci", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT") testMethod(t, r, "PUT")
testFormValues(t, r, values{ testJsonBody(t, r, values{
"token": "t", "token": "t",
"drone_url": "u", "drone_url": "u",
"enable_ssl_verification": "true", "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