-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathoapi_validate_test.go
More file actions
65 lines (51 loc) · 1.66 KB
/
oapi_validate_test.go
File metadata and controls
65 lines (51 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package nethttpmiddleware
import (
"fmt"
"testing"
"github.com/getkin/kin-openapi/openapi3filter"
)
func Test_determineStatusCodeForMultiError(t *testing.T) {
t.Run("returns HTTP 400 Bad Request when only `RequestError`s", func(t *testing.T) {
errs := []error{
&openapi3filter.RequestError{},
&openapi3filter.RequestError{},
}
expected := 400
actual := determineStatusCodeForMultiError(errs)
if expected != actual {
t.Errorf("Expected an HTTP %d to be returned, but received %d", expected, actual)
}
})
t.Run("returns HTTP 401 Unauthorized when only `SecurityRequirementsError`s", func(t *testing.T) {
errs := []error{
&openapi3filter.SecurityRequirementsError{},
&openapi3filter.SecurityRequirementsError{},
}
expected := 401
actual := determineStatusCodeForMultiError(errs)
if expected != actual {
t.Errorf("Expected an HTTP %d to be returned, but received %d", expected, actual)
}
})
t.Run("returns HTTP 500 Internal Server Error when mixed error types", func(t *testing.T) {
errs := []error{
&openapi3filter.RequestError{},
&openapi3filter.SecurityRequirementsError{},
}
expected := 500
actual := determineStatusCodeForMultiError(errs)
if expected != actual {
t.Errorf("Expected an HTTP %d to be returned, but received %d", expected, actual)
}
})
t.Run("returns HTTP 500 Internal Server Error when unknown error type(s) are seen", func(t *testing.T) {
errs := []error{
fmt.Errorf("this isn't a known error type"),
}
expected := 500
actual := determineStatusCodeForMultiError(errs)
if expected != actual {
t.Errorf("Expected an HTTP %d to be returned, but received %d", expected, actual)
}
})
}