forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_credential_binding_resource_test.go
98 lines (94 loc) · 2.49 KB
/
service_credential_binding_resource_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
package resources_test
import (
"encoding/json"
. "code.cloudfoundry.org/cli/resources"
"code.cloudfoundry.org/cli/types"
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/extensions/table"
. "github.com/onsi/gomega"
)
var _ = Describe("service credential binding resource", func() {
DescribeTable(
"Marshaling and Unmarshaling",
func(binding ServiceCredentialBinding, serialized string) {
By("marshaling", func() {
Expect(json.Marshal(binding)).To(MatchJSON(serialized))
})
By("unmarshaling", func() {
var parsed ServiceCredentialBinding
Expect(json.Unmarshal([]byte(serialized), &parsed)).NotTo(HaveOccurred())
Expect(parsed).To(Equal(binding))
})
},
Entry("empty", ServiceCredentialBinding{}, `{}`),
Entry("type", ServiceCredentialBinding{Type: "fake-type"}, `{"type": "fake-type"}`),
Entry("name", ServiceCredentialBinding{Name: "fake-name"}, `{"name": "fake-name"}`),
Entry("guid", ServiceCredentialBinding{GUID: "fake-guid"}, `{"guid": "fake-guid"}`),
Entry("service instance guid guid",
ServiceCredentialBinding{ServiceInstanceGUID: "fake-instance-guid"},
`{ "relationships": { "service_instance": { "data": { "guid": "fake-instance-guid" } } } }`,
),
Entry("app guid",
ServiceCredentialBinding{AppGUID: "fake-app-guid"},
`{ "relationships": { "app": { "data": { "guid": "fake-app-guid" } } } }`,
),
Entry(
"last operation",
ServiceCredentialBinding{
LastOperation: LastOperation{Type: CreateOperation, State: OperationInProgress},
},
`{
"last_operation": {
"type": "create",
"state": "in progress"
}
}`,
),
Entry(
"parameters",
ServiceCredentialBinding{
Parameters: types.NewOptionalObject(map[string]interface{}{
"foo": "bar",
}),
},
`{
"parameters": {
"foo": "bar"
}
}`,
),
Entry(
"everything",
ServiceCredentialBinding{
Type: AppBinding,
GUID: "fake-guid",
Name: "fake-name",
AppGUID: "fake-app-guid",
ServiceInstanceGUID: "fake-service-instance-guid",
Parameters: types.NewOptionalObject(map[string]interface{}{
"foo": "bar",
}),
},
`{
"type": "app",
"guid": "fake-guid",
"name": "fake-name",
"relationships": {
"service_instance": {
"data": {
"guid": "fake-service-instance-guid"
}
},
"app": {
"data": {
"guid": "fake-app-guid"
}
}
},
"parameters": {
"foo": "bar"
}
}`,
),
)
})