diff --git a/STEP_DEFINITIONS.md b/STEP_DEFINITIONS.md index 8e109d0..5c9ee08 100644 --- a/STEP_DEFINITIONS.md +++ b/STEP_DEFINITIONS.md @@ -21,7 +21,6 @@ This library provides these generic steps that should be useable across a variet | the following document exists in the "COLLECTION" collection: \_BODY\_ | put document BODY in the COLLECTION collection | Given | | I set the "KEY" header to "VALUE" | set a HTTP header of the request to the value | Given | | I GET "URL" | make a GET request to the provided URL | When | -| I GET "URL" without a request host | make a GET request without the host to the provided URL | When | | I DELETE "URL" | make a DELETE request to the provided URL | When | | I PUT "URL" "BODY" | make a PUT request to the provided URL with the given body | When | | I PATCH "URL" "BODY" | make a PATCH request to the provided URL with the given body | When | diff --git a/api_feature.go b/api_feature.go index f93f8ba..2847749 100644 --- a/api_feature.go +++ b/api_feature.go @@ -55,7 +55,6 @@ func (f *APIFeature) RegisterSteps(ctx *godog.ScenarioContext) { ctx.Step(`^I am authorised$`, f.IAmAuthorised) ctx.Step(`^I am not authorised$`, f.IAmNotAuthorised) ctx.Step(`^I GET "([^"]*)"$`, f.IGet) - ctx.Step(`^I GET "([^"]*)" without a request host$`, f.IGetWithoutRequestHost) ctx.Step(`^I POST "([^"]*)"$`, f.IPostToWithBody) ctx.Step(`^I PUT "([^"]*)"$`, f.IPut) ctx.Step(`^I PATCH "([^"]*)"$`, f.IPatch) @@ -103,11 +102,6 @@ func (f *APIFeature) IGet(path string) error { return f.makeRequest("GET", path, nil) } -// IGetWithoutRequestHost makes a get request without the host to the provided path with the current headers -func (f *APIFeature) IGetWithoutRequestHost(path string) error { - return f.makeRequestWithoutHost("GET", path, nil) -} - // IPostToWithBody makes a POST request to the provided path with the current headers and the body provided func (f *APIFeature) IPostToWithBody(path string, body *godog.DocString) error { return f.makeRequest("POST", path, []byte(body.Content)) @@ -145,25 +139,6 @@ func (f *APIFeature) makeRequest(method, path string, data []byte) error { return nil } -// Request is made without a host so that FromHeadersOrDefault() within dp-net uses the defaultURL to build links -func (f *APIFeature) makeRequestWithoutHost(method, path string, data []byte) error { - handler, err := f.Initialiser() - if err != nil { - return err - } - req := httptest.NewRequest(method, "http://foo"+path, bytes.NewReader(data)) - req.Host = "" - for key, value := range f.requestHeaders { - req.Header.Set(key, value) - } - - w := httptest.NewRecorder() - handler.ServeHTTP(w, req) - - f.HTTPResponse = w.Result() - return nil -} - // IShouldReceiveTheFollowingResponse asserts the response body and expected response body are equal func (f *APIFeature) IShouldReceiveTheFollowingResponse(expectedAPIResponse *godog.DocString) error { responseBody := f.HTTPResponse.Body diff --git a/examples/api/features/example.feature b/examples/api/features/example.feature index addbca0..ad1eb29 100644 --- a/examples/api/features/example.feature +++ b/examples/api/features/example.feature @@ -17,11 +17,4 @@ Feature: Example feature And I should receive the following response: """ 403 - Forbidden - """ - - Scenario: Example 3 endpoint scenario - When I GET "/example3" without a request host - Then I should receive the following JSON response with status "200": - """ - {"example_type": 3} """ \ No newline at end of file diff --git a/examples/api/main.go b/examples/api/main.go index bbc074b..e4e9df2 100644 --- a/examples/api/main.go +++ b/examples/api/main.go @@ -26,24 +26,11 @@ func ExampleHandler2(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "403 - Forbidden") } -func ExampleHandler3(w http.ResponseWriter, r *http.Request) { - data := struct { - ExampleType int `json:"example_type"` - }{ExampleType: 3} - - w.Header().Set("Content-Type", "application/json") - - resp, _ := json.Marshal(data) - - fmt.Fprintf(w, string(resp)) -} - func newRouter() http.Handler { router := mux.NewRouter().StrictSlash(true) router.HandleFunc("/example1", ExampleHandler1).Methods("GET") router.HandleFunc("/example2", ExampleHandler2).Methods("POST") - router.HandleFunc("/example3", ExampleHandler3).Methods("GET") return router }