Skip to content

Commit

Permalink
Add CATS test for File Based Service Bindings on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
klapkov committed Feb 7, 2025
1 parent 2445bf0 commit aa7ec08
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cats_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ var _ = SynchronizedBeforeSuite(func() []byte {
err = buildCmd.Run()
Expect(err).NotTo(HaveOccurred())

if Config.GetIncludeWindows() {
windowsBuildCmd := exec.Command("go", "build", "-o", "bin/catnip.exe")
windowsBuildCmd.Dir = "assets/catnip"
windowsBuildCmd.Env = append(os.Environ(),
"CGO_ENABLED=0",
"GOOS=windows",
"GOARCH=amd64",
)
windowsBuildCmd.Stdout = GinkgoWriter
windowsBuildCmd.Stderr = GinkgoWriter

err = windowsBuildCmd.Run()
Expect(err).NotTo(HaveOccurred())
}

doraFiles, err := os.ReadDir(assets.NewAssets().Dora)
Expect(err).NotTo(HaveOccurred())

Expand Down
12 changes: 12 additions & 0 deletions helpers/app_helpers/app_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ func CatnipWithArgs(appName string, args ...string) []string {
return pushArgs
}

func WindowsCatnipWithArgs(appName string, args ...string) []string {
pushArgs := []string{
"push", appName,
"-s", Config.GetWindowsStack(),
"-b", Config.GetBinaryBuildpackName(),
"-p", assets.NewAssets().Catnip,
"-c", "./catnip.exe",
}
pushArgs = append(pushArgs, args...)
return pushArgs
}

func BinaryWithArgs(appName string, args ...string) []string {
pushArgs := []string{
"push", appName,
Expand Down
89 changes: 89 additions & 0 deletions windows/file_based_service_bindings_win.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package windows

import (
"encoding/json"
"fmt"
"strings"

. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
services_test "github.com/cloudfoundry/cf-acceptance-tests/services"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
"github.com/cloudfoundry/cf-test-helpers/v2/generator"
"github.com/cloudfoundry/cf-test-helpers/v2/helpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)

var _ = WindowsDescribe("File Based Service Bindings", func() {
var appName, serviceName string

getEncodedFilepath := func(serviceName string, fileName string) string {
path := fmt.Sprintf("/etc/cf-service-bindings/%s/%s", serviceName, fileName)
return strings.Replace(path, "/", "%2F", -1)
}

checkFileContent := func(fileName string, content string) {
curlResponse := helpers.CurlApp(Config, appName, "/file/"+getEncodedFilepath(serviceName, fileName), "-L")
Expect(curlResponse).Should(ContainSubstring(content))
}

getServiceInstanceGuid := func(serviceName string) string {
serviceGuidCmd := cf.Cf("service", serviceName, "--guid")
Eventually(serviceGuidCmd).Should(Exit(0))
return strings.TrimSpace(string(serviceGuidCmd.Out.Contents()))
}

getServiceBindingGuid := func(appGuid string, instanceGuid string) string {
jsonResults := services_test.Response{}
bindingCurl := cf.Cf("curl", fmt.Sprintf("/v3/service_credential_bindings?app_guids=%s&service_instance_guids=%s", appGuid, instanceGuid)).Wait()
Expect(bindingCurl).To(Exit(0))
Expect(json.Unmarshal(bindingCurl.Out.Contents(), &jsonResults)).NotTo(HaveOccurred())
Expect(len(jsonResults.Resources)).To(BeNumerically(">", 0), "Expected to find at least one service binding.")
return jsonResults.Resources[0].GUID
}

BeforeEach(func() {
appName = random_name.CATSRandomName("APP")
serviceName = generator.PrefixedRandomName("cats", "svin")
})

AfterEach(func() {
app_helpers.AppReport(appName)
Eventually(cf.Cf("unbind-service", appName, serviceName).Wait()).Should(Exit(0))
Eventually(cf.Cf("delete", appName, "-f")).Should(Exit(0))
Eventually(cf.Cf("delete-service", serviceName, "-f").Wait()).Should(Exit(0))
})

It("creates the required files in the app container", func() {
tags := "list, of, tags"
creds := `{"username": "admin", "password":"pa55woRD"}`
Expect(cf.Cf("create-user-provided-service", serviceName, "-p", creds, "-t", tags).Wait()).To(Exit(0))
serviceGuid := getServiceInstanceGuid(serviceName)

Expect(cf.Cf("create-app", appName).Wait()).To(Exit(0))
appGuid := app_helpers.GetAppGuid(appName)

appFeatureUrl := fmt.Sprintf("/v3/apps/%s/features/file-based-service-bindings", appGuid)
Expect(cf.Cf("curl", appFeatureUrl, "-X", "PATCH", "-d", `{"enabled": true}`).Wait()).To(Exit(0))
Expect(cf.Cf("bind-service", appName, serviceName).Wait()).To(Exit(0))

Expect(cf.Cf(app_helpers.WindowsCatnipWithArgs(
appName,
"-m", DEFAULT_MEMORY_LIMIT)...,
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))

checkFileContent("binding-guid", getServiceBindingGuid(appGuid, serviceGuid))
checkFileContent("instance-guid", serviceGuid)
checkFileContent("instance-name", serviceName)
checkFileContent("label", "user-provided")
checkFileContent("name", serviceName)
checkFileContent("password", "pa55woRD")
checkFileContent("provider", "user-provided")
checkFileContent("tags", `["list","of","tags"]`)
checkFileContent("type", "user-provided")
checkFileContent("username", "admin")
})
})

0 comments on commit aa7ec08

Please sign in to comment.