forked from cloudfoundry/rep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rootfs_providers_test.go
118 lines (93 loc) · 2.74 KB
/
rootfs_providers_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package rep_test
import (
"encoding/json"
"net/url"
"code.cloudfoundry.org/rep"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("RootFSProviders", func() {
var (
arbitrary rep.ArbitraryRootFSProvider
fixedSet rep.FixedSetRootFSProvider
providers rep.RootFSProviders
providersJSON string
)
BeforeEach(func() {
arbitrary = rep.ArbitraryRootFSProvider{}
fixedSet = rep.NewFixedSetRootFSProvider("baz", "quux")
providers = rep.RootFSProviders{
"foo": arbitrary,
"bar": fixedSet,
}
providersJSON = `{
"foo": {
"type": "arbitrary"
},
"bar": {
"type": "fixed_set",
"set": {"baz":{}, "quux":{}}
}
}`
})
It("serializes", func() {
payload, err := json.Marshal(providers)
Expect(err).NotTo(HaveOccurred())
Expect(payload).To(MatchJSON(providersJSON))
})
It("deserializes", func() {
var providersResult rep.RootFSProviders
err := json.Unmarshal([]byte(providersJSON), &providersResult)
Expect(err).NotTo(HaveOccurred())
Expect(providersResult).To(Equal(providers))
})
Describe("Match", func() {
Describe("ArbitraryRootFSProvider", func() {
It("matches any URL", func() {
rootFS, err := url.Parse("some://url")
Expect(err).NotTo(HaveOccurred())
Expect(arbitrary.Match(*rootFS)).To(BeTrue())
})
})
Describe("FixedSetRootFSProvider", func() {
It("matches a URL in the set", func() {
rootFS, err := url.Parse("some:baz")
Expect(err).NotTo(HaveOccurred())
Expect(fixedSet.Match(*rootFS)).To(BeTrue())
})
It("does not match a URL not in the set", func() {
rootFS, err := url.Parse("some://baz-not-present/here")
Expect(err).NotTo(HaveOccurred())
Expect(fixedSet.Match(*rootFS)).To(BeFalse())
})
})
Describe("RootFSProviders", func() {
Context("for a scheme with an arbitrary provider", func() {
It("matches any url", func() {
rootFS, err := url.Parse("foo://any/url/is#ok")
Expect(err).NotTo(HaveOccurred())
Expect(providers.Match(*rootFS)).To(BeTrue())
})
})
Context("for a scheme with a fixed-set provider", func() {
It("matches for a url in the set", func() {
rootFS, err := url.Parse("bar:quux")
Expect(err).NotTo(HaveOccurred())
Expect(providers.Match(*rootFS)).To(BeTrue())
})
It("does not match for a url not in the set", func() {
rootFS, err := url.Parse("bar:quux/not?in=theset")
Expect(err).NotTo(HaveOccurred())
Expect(providers.Match(*rootFS)).To(BeFalse())
})
})
Context("for a scheme not in the map", func() {
It("does not match", func() {
rootFS, err := url.Parse("missingscheme://host/path")
Expect(err).NotTo(HaveOccurred())
Expect(providers.Match(*rootFS)).To(BeFalse())
})
})
})
})
})