Skip to content

Commit

Permalink
removed step
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan-p03 committed Jan 31, 2025
1 parent 7e5fec1 commit 256151b
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 46 deletions.
1 change: 0 additions & 1 deletion STEP_DEFINITIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
25 changes: 0 additions & 25 deletions api_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions examples/api/features/example.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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}
"""
13 changes: 0 additions & 13 deletions examples/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 256151b

Please sign in to comment.