forked from snyk/vervet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_test.go
89 lines (84 loc) · 2.33 KB
/
spec_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package vervet_test
import (
"testing"
qt "github.com/frankban/quicktest"
. "github.com/snyk/vervet"
"github.com/snyk/vervet/testdata"
)
func TestSpecs(t *testing.T) {
c := qt.New(t)
specs, err := LoadSpecVersions(testdata.Path("resources"))
c.Assert(err, qt.IsNil)
versions := specs.Versions()
c.Assert(versions, qt.HasLen, 4)
c.Assert(versions, qt.ContentEquals, []*Version{
mustParseVersion("2021-06-01"),
mustParseVersion("2021-06-04~experimental"),
mustParseVersion("2021-06-07"),
mustParseVersion("2021-06-13~beta"),
})
type expectResourceVersion struct {
version string
path string
}
tests := []struct {
query string
hasVersions []expectResourceVersion
}{{
query: "2021-07-01~experimental",
hasVersions: []expectResourceVersion{{
version: "2021-06-13~beta",
path: "/examples/hello-world",
}, {
version: "2021-06-13~beta",
path: "/examples/hello-world/{id}",
}, {
version: "2021-06-04~experimental",
path: "/orgs/{orgId}/projects",
}},
}, {
query: "2021-07-01~wip",
hasVersions: []expectResourceVersion{{
version: "2021-06-13~beta",
path: "/examples/hello-world",
}, {
version: "2021-06-13~beta",
path: "/examples/hello-world/{id}",
}, {
version: "2021-06-04~experimental",
path: "/orgs/{orgId}/projects",
}},
}, {
query: "2021-07-01~beta",
hasVersions: []expectResourceVersion{{
version: "2021-06-13~beta",
path: "/examples/hello-world",
}, {
version: "2021-06-13~beta",
path: "/examples/hello-world/{id}",
}},
}, {
query: "2021-07-01",
hasVersions: []expectResourceVersion{{
version: "2021-06-07",
path: "/examples/hello-world/{id}",
}},
}}
for i, t := range tests {
c.Logf("test#%d: %#v", i, t)
spec, err := specs.At(t.query)
c.Assert(err, qt.IsNil)
_, err = ExtensionString(spec.ExtensionProps, ExtSnykApiStability)
c.Assert(err, qt.ErrorMatches, `extension "x-snyk-api-stability" not found`)
m := map[expectResourceVersion]bool{}
for path, pathItem := range spec.Paths {
pathVersionStr, err := ExtensionString(pathItem.ExtensionProps, ExtSnykApiVersion)
c.Assert(err, qt.IsNil)
m[expectResourceVersion{version: pathVersionStr, path: path}] = true
}
c.Assert(m, qt.HasLen, len(t.hasVersions))
for _, hasVersion := range t.hasVersions {
c.Assert(m[hasVersion], qt.IsTrue)
}
}
}