-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
openapi_test.go
50 lines (38 loc) · 1.16 KB
/
openapi_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
package vulcain
import (
"net/url"
"testing"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
)
const openapiFixture = "./fixtures/openapi.yaml"
func TestNewOpenAPI(t *testing.T) {
assert.NotNil(t, newOpenAPI(openapiFixture, zap.NewNop()))
assert.Panics(t, func() {
newOpenAPI("notexists", zap.NewNop())
})
}
func TestGetRoute(t *testing.T) {
oa := newOpenAPI(openapiFixture, zap.NewNop())
u, _ := url.Parse("/oa/books/123")
assert.NotNil(t, oa.getRoute(u))
u, _ = url.Parse("/notexists")
assert.Nil(t, oa.getRoute(u))
}
func TestGetRelation(t *testing.T) {
oa := newOpenAPI(openapiFixture, zap.NewNop())
u, _ := url.Parse("/oa/books/123")
r := oa.getRelation(oa.getRoute(u), "/author", "456")
assert.Equal(t, "/oa/authors/456", r)
u, _ = url.Parse("/oa/books.json")
r = oa.getRelation(oa.getRoute(u), "/member/*", "1936")
assert.Equal(t, "/oa/books/1936", r)
u, _ = url.Parse("/oa/books.json")
r = oa.getRelation(oa.getRoute(u), "/notexists", "1891")
assert.Equal(t, "", r)
}
func TestGenerateLink(t *testing.T) {
oa := newOpenAPI(openapiFixture, zap.NewNop())
l := oa.generateLink("notexists", "nestor", "makhno")
assert.Equal(t, "", l)
}