Skip to content

Commit

Permalink
test: invalid car content type params
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Oct 31, 2023
1 parent 5ac5e33 commit 4cd1a11
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions gateway/handler_car_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,30 @@ func TestCarParams(t *testing.T) {
require.Equal(t, test.expectedDuplicates.String(), params.Duplicates.String())
}
})

t.Run("buildCarParams from Accept header: order and dups parsing (invalid)", func(t *testing.T) {
t.Parallel()

// below ensure the implicit default (DFS and no duplicates) is correctly inferred
// from the value read from Accept header
tests := []string{
"application/vnd.ipld.car; dups=invalid",
"application/vnd.ipld.car; order=invalid",
"application/vnd.ipld.car; order=dfs; dups=invalid",
"application/vnd.ipld.car; order=invalid; dups=y",
}
for _, test := range tests {
r := mustNewRequest(t, http.MethodGet, "http://example.com/", nil)
r.Header.Set("Accept", test)

mediaType, formatParams, err := customResponseFormat(r)
assert.NoError(t, err)
assert.Equal(t, carResponseFormat, mediaType)

_, err = buildCarParams(r, formatParams)
assert.ErrorContains(t, err, "unsupported application/vnd.ipld.car content type")
}
})
}

func TestContentTypeFromCarParams(t *testing.T) {
Expand Down

0 comments on commit 4cd1a11

Please sign in to comment.