-
Notifications
You must be signed in to change notification settings - Fork 4
/
callback_test.go
23 lines (20 loc) · 1.24 KB
/
callback_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
package openapi_test
import (
"testing"
openapi "github.com/nasa9084/go-openapi"
)
func TestCallback_Validate(t *testing.T) {
candidates := []candidate{
{"empty", &openapi.Callback{}, nil},
{"zero string", &openapi.Callback{"": &openapi.PathItem{}}, openapi.ErrRuntimeExprFormat},
{"example.com", &openapi.Callback{"https://example.com": &openapi.PathItem{}}, nil},
{"with url expr", &openapi.Callback{"https://example.com/{$url}": &openapi.PathItem{}}, nil},
{"with method expr", &openapi.Callback{"https://example.com/{$method}": &openapi.PathItem{}}, nil},
{"with body and flag", &openapi.Callback{"https://example.com/{$request.body#/user/uuid}": &openapi.PathItem{}}, nil},
{"with two expr", &openapi.Callback{"https://example.com/{$request.body#/user/uuid}/{$method}": &openapi.PathItem{}}, nil},
{"with invalid expr", &openapi.Callback{"https://example.com/{foo}": &openapi.PathItem{}}, openapi.ErrRuntimeExprFormat},
{"with empty flag", &openapi.Callback{"https://example.com/{$request.body#}": &openapi.PathItem{}}, openapi.ErrRuntimeExprFormat},
{"with second invalid", &openapi.Callback{"https://example.com/{$request.body#/user/uuid}/{$value}": &openapi.PathItem{}}, openapi.ErrRuntimeExprFormat},
}
testValidater(t, candidates)
}