@@ -23,9 +23,9 @@ func TestImposterHandler(t *testing.T) {
2323 var headers = make (http.Header )
2424 headers .Add ("Content-Type" , "application/json" )
2525
26- schemaFile := "test/testdata/schemas/create_gopher_request.json"
27- bodyFile := "test/testdata/responses/create_gopher_response.json"
28- bodyFileFake := "test/testdata/responses/create_gopher_response_fail.json"
26+ schemaFile := "test/testdata/imposters/ schemas/create_gopher_request.json"
27+ bodyFile := "test/testdata/imposters/ responses/create_gopher_response.json"
28+ bodyFileFake := "test/testdata/imposters/ responses/create_gopher_response_fail.json"
2929 body := `{"test":true}`
3030
3131 validRequest := Request {
@@ -75,15 +75,6 @@ func TestImposterHandler(t *testing.T) {
7575}
7676
7777func TestInvalidRequestWithSchema (t * testing.T ) {
78- wrongRequest := []byte (`{
79- "data": {
80- "type": "gophers",
81- "attributes": {
82- "name": "Zebediah",
83- "color": "Purple"
84- }
85- }
86- }` )
8778 validRequest := []byte (`{
8879 "data": {
8980 "type": "gophers",
@@ -93,23 +84,18 @@ func TestInvalidRequestWithSchema(t *testing.T) {
9384 }
9485 }
9586 }` )
96- notExistFile := "failSchema"
97- wrongSchema := "test/testdata/schemas/create_gopher_request_fail.json"
98- validSchema := "test/testdata/schemas/create_gopher_request.json"
9987
10088 var dataTest = []struct {
10189 name string
10290 imposter Imposter
10391 statusCode int
10492 request []byte
10593 }{
106- {"schema file not found" , Imposter {Request : Request {Method : "POST" , Endpoint : "/gophers" , SchemaFile : & notExistFile }}, http .StatusBadRequest , validRequest },
107- {"wrong schema" , Imposter {Request : Request {Method : "POST" , Endpoint : "/gophers" , SchemaFile : & wrongSchema }}, http .StatusBadRequest , validRequest },
108- {"request invalid" , Imposter {Request : Request {Method : "POST" , Endpoint : "/gophers" , SchemaFile : & validSchema }}, http .StatusBadRequest , wrongRequest },
10994 {"valid request no schema" , Imposter {Request : Request {Method : "POST" , Endpoint : "/gophers" }, Response : Response {Status : http .StatusOK , Body : "test ok" }}, http .StatusOK , validRequest },
11095 }
11196
11297 for _ , tt := range dataTest {
98+
11399 t .Run (tt .name , func (t * testing.T ) {
114100 req , err := http .NewRequest ("POST" , "/gophers" , bytes .NewBuffer (tt .request ))
115101 if err != nil {
@@ -137,7 +123,7 @@ func TestInvalidHeaders(t *testing.T) {
137123 }
138124 }
139125 }` )
140- schemaFile := "test/testdata/schemas/create_gopher_request.json"
126+ schemaFile := "test/testdata/imposters/ schemas/create_gopher_request.json"
141127 var expectedHeaders = make (http.Header )
142128 expectedHeaders .Add ("Content-Type" , "application/json" )
143129 expectedHeaders .Add ("Authorization" , "Bearer gopher" )
0 commit comments