Skip to content

Commit 80d180b

Browse files
authored
Test Singleton Resources (#16)
This functionality isn't covered by any existing unit tests, so add in a basic test to ensure it works and is guarded.
1 parent c03a289 commit 80d180b

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

test/unit/fixtures/fixtures.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ const (
3737
// ServiceInstanceName is a name to use for a service instance.
3838
ServiceInstanceName = "pinkiepie"
3939

40+
// AlternateServiceInstanceName is a name to use for another service instance.
41+
AlternateServiceInstanceName = "rainbowdash"
42+
4043
// ServiceBindingName is a name to use for a service binding.
4144
ServiceBindingName = "spike"
4245

@@ -128,10 +131,14 @@ var (
128131
},
129132
},
130133
{
131-
Name: "test-template",
132-
// Populated by the configuration function.
134+
Name: "test-template",
133135
Template: &runtime.RawExtension{Raw: []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"{{registry \"instance-name\" | json}}"},"spec":{"containers":[{"name":"image","image":"name/image:tag"}],"automountServiceAccountToken":"{{true | json}}","priority":"{{0 | json}}","dnsConfig":"{{snippet \"dns-snippet\" | json}}","hostname":"{{parameter \"/hostname\" | json}}"}}`)},
134136
},
137+
{
138+
Name: "test-singleton",
139+
Singleton: true,
140+
Template: &runtime.RawExtension{Raw: []byte(`{"apiVersion":"v1","kind":"Pod","metadata":{"name":"singleton"}}`)},
141+
},
135142
},
136143
Bindings: []v1.ConfigurationBinding{
137144
{
@@ -151,6 +158,7 @@ var (
151158
},
152159
Templates: []string{
153160
"test-template",
161+
"test-singleton",
154162
},
155163
},
156164
ServiceBinding: &v1.ServiceBrokerTemplateList{

test/unit/serviceinstance_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@ func TestServiceInstanceCreate(t *testing.T) {
3737
util.MustCreateServiceInstanceSuccessfully(t, fixtures.ServiceInstanceName, req)
3838
}
3939

40+
// TestServiceInstanceCreateSingleton tests that the service broker accepts a
41+
// minimal service instance creation and allows multiple instances sharing a
42+
// singleton resource.
43+
func TestServiceInstanceCreateSingleton(t *testing.T) {
44+
defer mustReset(t)
45+
46+
configuration := fixtures.BasicConfiguration()
47+
util.MustReplaceBrokerConfig(t, clients, configuration)
48+
49+
req := fixtures.BasicServiceInstanceCreateRequest()
50+
util.MustCreateServiceInstanceSuccessfully(t, fixtures.ServiceInstanceName, req)
51+
util.MustCreateServiceInstanceSuccessfully(t, fixtures.AlternateServiceInstanceName, req)
52+
}
53+
4054
// TestServiceInstanceCreateNotAynchronous tests that the service broker rejects service
4155
// instance creation that isn't asynchronous.
4256
func TestServiceInstanceCreateNotAynchronous(t *testing.T) {

0 commit comments

Comments
 (0)