Skip to content

Commit

Permalink
Not Found handling tweaks (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
callumevans authored Dec 12, 2024
1 parent acf8205 commit fe74a7f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/offline-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install Hurl
run: |
VERSION=5.0.1
VERSION=6.0.0
curl --location --remote-name https://github.com/Orange-OpenSource/hurl/releases/download/$VERSION/hurl_${VERSION}_amd64.deb
sudo apt update && sudo apt install ./hurl_${VERSION}_amd64.deb
Expand Down
11 changes: 9 additions & 2 deletions offline/offline.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ func Run(filePath string, moduleName string, port string) error {

r := mux.NewRouter()

// 404 for not found
// Not Found handlers
r.MethodNotAllowedHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`{"message": "Not Found"}`))
})

r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
w.Write([]byte(`{"message": "Not Found"}`))
})

// Start compiling and serving each handler
Expand Down
7 changes: 0 additions & 7 deletions offline/offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,4 @@ func TestPrintConfig(t *testing.T) {
endpoint, output)
}
}

// Test order of endpoints (GET before POST)
getIndex := strings.Index(output, "GET")
postIndex := strings.Index(output, "POST")
if getIndex > postIndex {
t.Error("Expected GET endpoint to appear before POST endpoint")
}
}
2 changes: 1 addition & 1 deletion terrable_build
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = 0.3.0
version = 0.3.1
11 changes: 11 additions & 0 deletions tests/requests/echo_bad_method.hurl
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
# Hit a route that exists but ot for the method in the request
DELETE http://127.0.0.1:8081/
HTTP 404

[Asserts]
jsonpath "$.message" == "Not Found"

# Hit a route that doesn't exist at all
GET http://127.0.0.1:8081/{{newUuid}}
HTTP 404

[Asserts]
jsonpath "$.message" == "Not Found"

0 comments on commit fe74a7f

Please sign in to comment.