-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameter_list_test.go
67 lines (56 loc) · 1.74 KB
/
parameter_list_test.go
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
66
67
package openapi_test
import (
"testing"
"github.com/MarkRosemaker/openapi"
)
func TestParameterList_Validate_Error(t *testing.T) {
t.Parallel()
err := openapi.ParameterList{{
Value: &openapi.Parameter{
Name: "foo", In: openapi.ParameterLocationQuery,
Schema: &openapi.Schema{Type: openapi.TypeString},
},
}, {
Value: &openapi.Parameter{
Name: "foo", In: openapi.ParameterLocationQuery,
Schema: &openapi.Schema{Type: openapi.TypeString},
},
}}.Validate()
if err == nil {
t.Fatal("expected error")
} else if want := `[0].name ("foo") is invalid: not unique in query
[1].name ("foo") is invalid: not unique in query`; err.Error() != want {
t.Fatalf("want: %v, got: %v", want, err)
}
}
func TestParameterList_In(t *testing.T) {
t.Parallel()
var list openapi.ParameterList
if inPath := list.InPath(); inPath != nil {
t.Fatalf("want: nil, got: %v", inPath)
}
if inQuery := list.InQuery(); inQuery != nil {
t.Fatalf("want: nil, got: %v", inQuery)
}
list = append(list, &openapi.ParameterRef{
Value: &openapi.Parameter{
Name: "foo", In: openapi.ParameterLocationQuery,
Schema: &openapi.Schema{Type: openapi.TypeString},
},
}, &openapi.ParameterRef{
Value: &openapi.Parameter{
Name: "bar", In: openapi.ParameterLocationPath,
Schema: &openapi.Schema{Type: openapi.TypeString},
},
})
if inPath := list.InPath(); len(inPath) != 1 {
t.Fatalf("want: 1, got: %v", len(inPath))
} else if want := "bar"; inPath[0].Value.Name != want {
t.Fatalf("want: %q, got: %q", want, inPath[0].Value.Name)
}
if inQuery := list.InQuery(); len(inQuery) != 1 {
t.Fatalf("want: 1, got: %v", len(inQuery))
} else if want := "foo"; inQuery[0].Value.Name != want {
t.Fatalf("want: %q, got: %q", want, inQuery[0].Value.Name)
}
}