Skip to content

Commit 61d6a73

Browse files
committed
Add docker app test to file-based service binding test
1 parent 6840265 commit 61d6a73

File tree

7 files changed

+74
-2
lines changed

7 files changed

+74
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ Test Group Name| Description
359359
`cnb` | Tests our ability to use cloud native buildpacks.
360360
`detect` | Tests the ability of the platform to detect the correct buildpack for compiling an application if no buildpack is explicitly specified.
361361
`docker`| Tests our ability to run docker containers on Diego and that we handle docker metadata correctly.
362-
`file-based service bindings`| Tests file-based service bindings for a buildpack and a CNB app.
362+
`file-based service bindings`| Tests file-based service bindings for a buildpack app, a CNB app and a Docker app.
363363
`internet_dependent`| Tests the feature of being able to specify a buildpack via a Github URL. As such, this depends on your Cloud Foundry application containers having access to the Internet. You should take into account the configuration of the network into which you've deployed your Cloud Foundry, as well as any security group settings applied to application containers.
364364
`isolation_segments` | This test group requires that Diego be deployed with a minimum of 2 cells. One of those cells must have been deployed with a `placement_tag`. If the deployment has been deployed with a routing isolation segment, `isolation_segment_domain` must also be set. For more information, please refer to the [Isolation Segments documentation](https://docs.cloudfoundry.org/adminguide/isolation-segments.html).
365365
`route_services` | Tests the [Route Services](https://docs.cloudfoundry.org/services/route-services.html) feature of Cloud Foundry.

cats_suite_helpers/cats_suite_helpers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func CNBDescribe(description string, callback func()) bool {
112112
const (
113113
BuildpackLifecycle string = "buildpack"
114114
CNBLifecycle = "CNB"
115+
DockerLifecycle = "Docker"
115116
)
116117

117118
func FileBasedServiceBindingsDescribe(description string, lifecycle string, callback func()) bool {
@@ -123,6 +124,9 @@ func FileBasedServiceBindingsDescribe(description string, lifecycle string, call
123124
if lifecycle == CNBLifecycle && (!Config.GetIncludeFileBasedServiceBindings() || !Config.GetIncludeCNB()) {
124125
Skip(skip_messages.SkipFileBasedServiceBindingsCnbApp)
125126
}
127+
if lifecycle == DockerLifecycle && (!Config.GetIncludeFileBasedServiceBindings() || !Config.GetIncludeDocker()) {
128+
Skip(skip_messages.SkipFileBasedServiceBindingsDockerApp)
129+
}
126130
})
127131
Describe(description, callback)
128132
})

file_based_service_bindings/file_based_service_bindings.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ var _ = FileBasedServiceBindingsDescribe("Enabling file based service binding fo
2525
callback(CNBLifecycle)
2626
})
2727

28+
var _ = FileBasedServiceBindingsDescribe("Enabling file based service binding for a Docker app", DockerLifecycle, func() {
29+
callback(DockerLifecycle)
30+
})
31+
32+
2833
var callback = func(lifecycle string) {
2934
var appName, serviceName string
3035

@@ -65,7 +70,7 @@ var callback = func(lifecycle string) {
6570
Eventually(cf.Cf("delete-service", serviceName, "-f").Wait()).Should(Exit(0))
6671
})
6772

68-
It("creates the required files in the app container", func() {
73+
FIt("creates the required files in the app container", func() {
6974
tags := "list, of, tags"
7075
creds := `{"username": "admin", "password":"pa55woRD"}`
7176
Expect(cf.Cf("create-user-provided-service", serviceName, "-p", creds, "-t", tags).Wait()).To(Exit(0))
@@ -77,6 +82,9 @@ var callback = func(lifecycle string) {
7782
if lifecycle == CNBLifecycle {
7883
Expect(cf.Cf("create-app", appName, "--app-type", "cnb", "--buildpack", Config.GetGoBuildpackName()).Wait()).To(Exit(0))
7984
}
85+
if lifecycle == DockerLifecycle {
86+
Expect(cf.Cf("create-app", appName, "--app-type", "docker").Wait()).To(Exit(0))
87+
}
8088
appGuid := app_helpers.GetAppGuid(appName)
8189

8290
appFeatureUrl := fmt.Sprintf("/v3/apps/%s/features/file-based-service-bindings", appGuid)
@@ -100,6 +108,14 @@ var callback = func(lifecycle string) {
100108
"-p", assets.NewAssets().CatnipSrc,
101109
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
102110
}
111+
if lifecycle == DockerLifecycle {
112+
Expect(cf.Cf(
113+
"push",
114+
appName,
115+
"--docker-image", Config.GetCatnipDockerAppImage(),
116+
"-m", DEFAULT_MEMORY_LIMIT,
117+
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
118+
}
103119

104120
checkFileContent("binding-guid", getServiceBindingGuid(appGuid, serviceGuid))
105121
checkFileContent("instance-guid", serviceGuid)

helpers/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ type CatsConfig interface {
111111
SleepTimeoutDuration() time.Duration
112112

113113
GetPublicDockerAppImage() string
114+
GetCatnipDockerAppImage() string
114115
}
115116

116117
func NewCatsConfig(path string) (CatsConfig, error) {

helpers/config/config_struct.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ type config struct {
116116
PrivateDockerRegistryUsername *string `json:"private_docker_registry_username"`
117117
PrivateDockerRegistryPassword *string `json:"private_docker_registry_password"`
118118
PublicDockerAppImage *string `json:"public_docker_app_image"`
119+
CatnipDockerAppImage *string `json:"catnip_docker_app_image"`
119120

120121
UnallocatedIPForSecurityGroup *string `json:"unallocated_ip_for_security_group"`
121122

@@ -240,6 +241,8 @@ func getDefaults() config {
240241
defaults.PrivateDockerRegistryUsername = ptrToString("")
241242
defaults.PrivateDockerRegistryPassword = ptrToString("")
242243
defaults.PublicDockerAppImage = ptrToString("cloudfoundry/diego-docker-app:latest")
244+
// TODO use "latest" tag (?)
245+
defaults.CatnipDockerAppImage = ptrToString("ghcr.io/cloudfoundry/catnip-app:file-based-service-bindings-docker-app")
243246

244247
defaults.UnallocatedIPForSecurityGroup = ptrToString("10.0.244.255")
245248

@@ -292,6 +295,12 @@ func validateConfig(config *config) error {
292295

293296
}
294297

298+
err = validateCatnipDockerAppImage(config)
299+
if err != nil {
300+
errs = errors.Join(errs, err)
301+
302+
}
303+
295304
err = validatePrivateDockerRegistry(config)
296305
if err != nil {
297306
errs = errors.Join(errs, err)
@@ -602,6 +611,16 @@ func validatePublicDockerAppImage(config *config) error {
602611
return nil
603612
}
604613

614+
func validateCatnipDockerAppImage(config *config) error {
615+
if config.CatnipDockerAppImage == nil {
616+
return fmt.Errorf("* 'catnip_docker_app_image' must not be null")
617+
}
618+
if config.GetCatnipDockerAppImage() == "" {
619+
return fmt.Errorf("* Invalid configuration: 'catnip_docker_app_image' must be set to a valid image source")
620+
}
621+
return nil
622+
}
623+
605624
func validatePrivateDockerRegistry(config *config) error {
606625
if config.IncludePrivateDockerRegistry == nil {
607626
return fmt.Errorf("* 'include_private_docker_registry' must not be null")
@@ -1123,6 +1142,10 @@ func (c *config) GetPublicDockerAppImage() string {
11231142
return *c.PublicDockerAppImage
11241143
}
11251144

1145+
func (c *config) GetCatnipDockerAppImage() string {
1146+
return *c.CatnipDockerAppImage
1147+
}
1148+
11261149
func (c *config) GetUnallocatedIPForSecurityGroup() string {
11271150
return *c.UnallocatedIPForSecurityGroup
11281151
}

helpers/config/config_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type testConfig struct {
4242
PrivateDockerRegistryUsername *string `json:"private_docker_registry_username,omitempty"`
4343
PrivateDockerRegistryPassword *string `json:"private_docker_registry_password,omitempty"`
4444
PublicDockerAppImage *string `json:"public_docker_app_image,omitempty"`
45+
CatnipDockerAppImage *string `json:"catnip_docker_app_image,omitempty"`
4546

4647
IsolationSegmentName *string `json:"isolation_segment_name,omitempty"`
4748
IsolationSegmentDomain *string `json:"isolation_segment_domain,omitempty"`
@@ -633,6 +634,32 @@ var _ = Describe("Config", func() {
633634
})
634635
})
635636

637+
Context("when including catnip_docker_app_image", func() {
638+
Context("when image name is set", func() {
639+
var image = "some-image"
640+
BeforeEach(func() {
641+
testCfg.CatnipDockerAppImage = ptrToString(image)
642+
})
643+
644+
It("has the value in the config", func() {
645+
config, err := cfg.NewCatsConfig(tmpFilePath)
646+
Expect(err).NotTo(HaveOccurred())
647+
Expect(config.GetCatnipDockerAppImage()).To(Equal(image))
648+
})
649+
})
650+
651+
Context("when image is an empty string", func() {
652+
BeforeEach(func() {
653+
testCfg.CatnipDockerAppImage = ptrToString("")
654+
})
655+
656+
It("returns an error", func() {
657+
_, err := cfg.NewCatsConfig(tmpFilePath)
658+
Expect(err).To(MatchError("* Invalid configuration: 'catnip_docker_app_image' must be set to a valid image source"))
659+
})
660+
})
661+
})
662+
636663
Context("when including isolation segment tests", func() {
637664
BeforeEach(func() {
638665
testCfg.IncludeIsolationSegments = ptrToBool(true)

helpers/skip_messages/skip_messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const SkipCNBMessage = `Skipping this test because config.IncludeCNB is set to '
1111
NOTE: Ensure CNB lifecycle is enabled on your platform before enabling this test.`
1212
const SkipFileBasedServiceBindingsBuildpackApp = `Skipping this test because config.IncludeFileBasedServiceBindings is set to 'false'.`
1313
const SkipFileBasedServiceBindingsCnbApp = `Skipping this test because config.IncludeFileBasedServiceBindings and/or config.IncludeCNB are set to 'false'.`
14+
const SkipFileBasedServiceBindingsDockerApp = `Skipping this test because config.IncludeFileBasedServiceBindings and/or config.IncludeDocker are set to 'false'.`
1415
const SkipInternetDependentMessage = `Skipping this test because config.IncludeInternetDependent is set to 'false'.
1516
NOTE: Ensure that your platform has access to the internet before running this test.`
1617
const SkipPrivateDockerRegistryMessage = `Skipping this test because config.IncludePrivateDockerRegistry is set to 'false'.

0 commit comments

Comments
 (0)