-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_test.go
More file actions
80 lines (65 loc) · 2.23 KB
/
start_test.go
File metadata and controls
80 lines (65 loc) · 2.23 KB
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
package duty
import (
"net/url"
"strconv"
"github.com/flanksource/duty/api"
ginkgo "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = ginkgo.Describe("PostgREST configuration", func() {
ginkgo.It("resolves localhost port 0 to a bindable port and updates the URL", func() {
config := api.Config{
Postgrest: api.PostgrestConfig{
URL: "http://localhost:0",
JWTSecret: "configured-secret",
},
}
configured, startLocal, err := configurePostgrest(config)
Expect(err).ToNot(HaveOccurred())
Expect(startLocal).To(BeTrue())
Expect(configured.Postgrest.Port).To(BeNumerically(">", 0))
Expect(configured.Postgrest.URL).ToNot(Equal("http://localhost:0"))
parsed, err := url.Parse(configured.Postgrest.URL)
Expect(err).ToNot(HaveOccurred())
Expect(parsed.Hostname()).To(Equal("localhost"))
Expect(parsed.Port()).To(Equal(strconv.Itoa(configured.Postgrest.Port)))
})
ginkgo.It("keeps an explicit localhost port", func() {
config := api.Config{
Postgrest: api.PostgrestConfig{
URL: "http://localhost:3000",
JWTSecret: "configured-secret",
},
}
configured, startLocal, err := configurePostgrest(config)
Expect(err).ToNot(HaveOccurred())
Expect(startLocal).To(BeTrue())
Expect(configured.Postgrest.Port).To(Equal(3000))
Expect(configured.Postgrest.URL).To(Equal("http://localhost:3000"))
})
ginkgo.It("does not start local PostgREST for remote URLs", func() {
config := api.Config{
Postgrest: api.PostgrestConfig{
URL: "http://postgrest.default.svc:3000",
},
}
configured, startLocal, err := configurePostgrest(config)
Expect(err).ToNot(HaveOccurred())
Expect(startLocal).To(BeFalse())
Expect(configured.Postgrest.Port).To(Equal(3000))
Expect(configured.Postgrest.URL).To(Equal("http://postgrest.default.svc:3000"))
})
ginkgo.It("does not configure PostgREST when disabled", func() {
config := api.Config{
Postgrest: api.PostgrestConfig{
URL: "http://localhost:0",
Disable: true,
},
}
configured, startLocal, err := configurePostgrest(config)
Expect(err).ToNot(HaveOccurred())
Expect(startLocal).To(BeFalse())
Expect(configured.Postgrest.Port).To(Equal(0))
Expect(configured.Postgrest.URL).To(Equal("http://localhost:0"))
})
})