Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xwa153 committed Aug 3, 2023
1 parent 071d612 commit 58e9ec3
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/resource/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ func TestResourceReadHandler(t *testing.T) {
require.Equal(t, "Keith Urban", result["data"].(map[string]any)["name"])
})

t.Run("should not be found if resource not exist", func(t *testing.T) {
rsp := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/demo/v2/artist/keith-not-exist?partition=default&peer_name=local&namespace=default&consistent", nil)

req.Header.Add("x-consul-token", testACLTokenArtistReadPolicy)

v2ArtistHandler.ServeHTTP(rsp, req)

require.Equal(t, http.StatusNotFound, rsp.Result().StatusCode)
})

t.Run("should be blocked if the token is not authorized", func(t *testing.T) {
rsp := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/demo/v2/artist/keith-urban?partition=default&peer_name=local&namespace=default&consistent", nil)
Expand Down

0 comments on commit 58e9ec3

Please sign in to comment.