-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improved tests, fixed a few small issues
- Loading branch information
1 parent
b8d2334
commit 2014487
Showing
10 changed files
with
525 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package huma | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/go-chi/chi" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBlankConfig(t *testing.T) { | ||
adapter := &testAdapter{chi.NewMux()} | ||
|
||
assert.NotPanics(t, func() { | ||
NewAPI(Config{}, adapter) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package huma | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Ensure the default error model satisfies these interfaces. | ||
var _ StatusError = (*ErrorModel)(nil) | ||
var _ ContentTypeFilter = (*ErrorModel)(nil) | ||
|
||
func TestError(t *testing.T) { | ||
err := &ErrorModel{ | ||
Status: 400, | ||
Detail: "test err", | ||
} | ||
|
||
// Add some children. | ||
err.Add(&ErrorDetail{ | ||
Message: "test detail", | ||
Location: "body.foo", | ||
Value: "bar", | ||
}) | ||
|
||
err.Add(fmt.Errorf("plain error")) | ||
|
||
// Confirm errors were added. | ||
assert.Equal(t, "test err", err.Error()) | ||
assert.Len(t, err.Errors, 2) | ||
assert.Equal(t, "test detail (body.foo: bar)", err.Errors[0].Error()) | ||
assert.Equal(t, "plain error", err.Errors[1].Error()) | ||
|
||
// Ensure problem content types. | ||
assert.Equal(t, "application/problem+json", err.ContentType("application/json")) | ||
assert.Equal(t, "application/problem+cbor", err.ContentType("application/cbor")) | ||
assert.Equal(t, "other", err.ContentType("other")) | ||
} | ||
|
||
func TestErrorResponses(t *testing.T) { | ||
// NotModified has a slightly different signature. | ||
assert.Equal(t, 304, Status304NotModified().GetStatus()) | ||
|
||
for _, item := range []struct { | ||
constructor func(msg string, errs ...error) StatusError | ||
expected int | ||
}{ | ||
{Error400BadRequest, 400}, | ||
{Error401Unauthorized, 401}, | ||
{Error403Forbidden, 403}, | ||
{Error404NotFound, 404}, | ||
{Error405MethodNotAllowed, 405}, | ||
{Error406NotAcceptable, 406}, | ||
{Error409Conflict, 409}, | ||
{Error410Gone, 410}, | ||
{Error412PreconditionFailed, 412}, | ||
{Error415UnsupportedMediaType, 415}, | ||
{Error422UnprocessableEntity, 422}, | ||
{Error429TooManyRequests, 429}, | ||
{Error500InternalServerError, 500}, | ||
{Error501NotImplemented, 501}, | ||
{Error502BadGateway, 502}, | ||
{Error503ServiceUnavailable, 503}, | ||
{Error504GatewayTimeout, 504}, | ||
} { | ||
err := item.constructor("test") | ||
assert.Equal(t, item.expected, err.GetStatus()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.