-
Notifications
You must be signed in to change notification settings - Fork 171
/
app_stack.go
153 lines (124 loc) · 3.89 KB
/
app_stack.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package apps
import (
"fmt"
"os"
"path"
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
archive_helpers "code.cloudfoundry.org/archiver/extractor/test_helper"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/skip_messages"
"github.com/cloudfoundry/cf-test-helpers/v2/cf"
"github.com/cloudfoundry/cf-test-helpers/v2/helpers"
"github.com/cloudfoundry/cf-test-helpers/v2/workflowhelpers"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = AppsDescribe("Specifying a specific stack", func() {
var (
appName string
buildpackName string
appPath string
buildpackPath string
buildpackArchivePath string
tmpdir string
)
matchingFilename := func(appName string) string {
return fmt.Sprintf("stack-match-%s", appName)
}
BeforeEach(func() {
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
buildpackName = CATSRandomName("BPK")
appName = CATSRandomName("APP")
var err error
tmpdir, err = os.MkdirTemp("", "stack")
Expect(err).ToNot(HaveOccurred())
appPath, err = os.MkdirTemp(tmpdir, "matching-app")
Expect(err).ToNot(HaveOccurred())
buildpackPath, err = os.MkdirTemp(tmpdir, "matching-buildpack")
Expect(err).ToNot(HaveOccurred())
buildpackArchivePath = path.Join(buildpackPath, "buildpack.zip")
archive_helpers.CreateZipArchive(buildpackArchivePath, []archive_helpers.ArchiveFile{
{
Name: "bin/compile",
Body: `#!/usr/bin/env bash
sleep 5
cat /etc/lsb-release
sleep 10
`,
},
{
Name: "bin/detect",
Body: fmt.Sprintf(`#!/bin/bash
if [ -f "${1}/%s" ]; then
echo Simple
else
echo no
exit 1
fi
`, matchingFilename(appName)),
},
{
Name: "bin/release",
Body: `#!/usr/bin/env bash
cat <<EOF
---
config_vars:
PATH: bin:/usr/local/bin:/usr/bin:/bin
FROM_BUILD_PACK: "yes"
default_process_types:
web: while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; echo -e "\$(cat /etc/lsb-release)"; } | nc -q 1 -l \$PORT; done
EOF
`,
},
})
_, err = os.Create(path.Join(appPath, matchingFilename(appName)))
Expect(err).ToNot(HaveOccurred())
_, err = os.Create(path.Join(appPath, "some-file"))
Expect(err).ToNot(HaveOccurred())
createBuildpack := cf.Cf("create-buildpack", buildpackName, buildpackArchivePath, "1").Wait()
Expect(createBuildpack).Should(Exit(0))
Expect(createBuildpack).Should(Say("Creating"))
Expect(createBuildpack).Should(Say("OK"))
Expect(createBuildpack).Should(Say("Uploading"))
Expect(createBuildpack).Should(Say("OK"))
})
})
AfterEach(func() {
app_helpers.AppReport(appName)
Expect(cf.Cf("delete", appName, "-f", "-r").Wait()).To(Exit(0))
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
Expect(cf.Cf("delete-buildpack", buildpackName, "-f").Wait()).To(Exit(0))
})
os.RemoveAll(tmpdir)
})
Context("when stack(s) are specified", func() {
It("uses stack(s) for staging and running", func() {
stacks := Config.GetStacks()
if len(stacks) == 0 {
Skip(skip_messages.SkipNoAlternateStacksMessage)
}
for _, stackName := range stacks {
By(fmt.Sprintf("testing stack: %s", stackName))
var expectedLSBRelease string
switch stackName {
case "cflinuxfs4":
expectedLSBRelease = "DISTRIB_CODENAME=jammy"
}
push := cf.Cf("push", appName,
"-b", buildpackName,
"-m", DEFAULT_MEMORY_LIMIT,
"-p", appPath,
"-s", stackName,
).Wait(Config.CfPushTimeoutDuration())
Expect(push).To(Exit(0))
Expect(push).To(Say(expectedLSBRelease))
Eventually(func() string {
return helpers.CurlAppRoot(Config, appName)
}).Should(ContainSubstring(expectedLSBRelease))
}
})
})
})