-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
124 lines (119 loc) · 2.5 KB
/
main_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
119
120
121
122
123
124
package main_test
import (
. "github.com/cloudfoundry-community/vcap-squash"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Main", func() {
var vcap string
var result []string
var expected = func(vals ...interface{}) {
Ω(result).Should(ConsistOf(vals...))
}
JustBeforeEach(func() {
result = Process(vcap)
})
It("should be empty", func() {
expected()
})
Context("when `VCAP_SERVICES` is set", func() {
Context("with a `user-provided` service", func() {
BeforeEach(func() {
vcap = `{
"user-provided": [{
"name": "hi",
"credentials": {
"uri": "http://www.a.b.com",
"username": "greeter"
}
}]
}`
})
It("flattens the service", func() {
expected(
`export HI_URI="http://www.a.b.com"`,
`export HI_USERNAME="greeter"`,
)
})
Context("that has nested objects", func() {
BeforeEach(func() {
vcap = `{
"user-provided": [{
"name": "NeSt",
"credentials": {
"a": {
"b": "c",
"e": 1
}
}
}]
}`
})
It("flattens the service", func() {
expected(
`export NEST_A_B="c"`,
`export NEST_A_E=1`,
)
})
})
})
Context("with a marketplace service", func() {
BeforeEach(func() {
vcap = `{ "p-mysql": [{
"name": "my-mysql-instance",
"credentials": {
"username": "x",
"password": "y",
"port": 1234
}
}] }`
})
It("flattens the service", func() {
expected(
`export MY_MYSQL_INSTANCE_USERNAME="x"`,
`export MY_MYSQL_INSTANCE_PASSWORD="y"`,
`export MY_MYSQL_INSTANCE_PORT=1234`,
)
})
})
Context("array fields", func() {
BeforeEach(func() {
vcap = `{ "user-provided": [{
"name": "svc",
"credentials": {
"names": [ "abc", 123 ]
}
}] }`
})
It("flattens with index", func() {
expected(
`export SVC_NAMES_0="abc"`,
`export SVC_NAMES_1=123`,
)
})
Context("that contain non-primitives", func() {
BeforeEach(func() {
vcap = `{ "user-provided": [{
"name": "svc",
"credentials": {
"apps": [ {
"name": "app1"
}, {
"name": "app2",
"nested": { "x": "yz" }
}, "third" ]
}
}] }`
})
It("includes index and field", func() {
expected(
`export SVC_APPS_0_NAME="app1"`,
`export SVC_APPS_1_NAME="app2"`,
`export SVC_APPS_1_NESTED_X="yz"`,
`export SVC_APPS_2="third"`,
)
})
})
})
})
})