forked from cloudfoundry/cf-acceptance-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app_staging_environment.go
132 lines (107 loc) · 3.34 KB
/
app_staging_environment.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
package apps
import (
"fmt"
"io/ioutil"
"os"
"path"
. "github.com/cloudfoundry/cf-acceptance-tests/cats_suite_helpers"
archive_helpers "code.cloudfoundry.org/archiver/extractor/test_helper"
"github.com/cloudfoundry-incubator/cf-test-helpers/cf"
"github.com/cloudfoundry-incubator/cf-test-helpers/workflowhelpers"
"github.com/cloudfoundry/cf-acceptance-tests/helpers/app_helpers"
. "github.com/cloudfoundry/cf-acceptance-tests/helpers/random_name"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gbytes"
. "github.com/onsi/gomega/gexec"
)
var _ = AppsDescribe("Buildpack Environment", func() {
var (
appName string
BuildpackName string
appPath string
buildpackPath string
buildpackArchivePath string
tmpdir string
)
matchingFilename := func(appName string) string {
return fmt.Sprintf("buildpack-environment-match-%s", appName)
}
BeforeEach(func() {
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
BuildpackName = CATSRandomName("BPK")
appName = CATSRandomName("APP")
var err error
tmpdir, err = ioutil.TempDir("", "buildpack_env")
Expect(err).ToNot(HaveOccurred())
appPath, err = ioutil.TempDir(tmpdir, "matching-app")
Expect(err).ToNot(HaveOccurred())
buildpackPath, err = ioutil.TempDir(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
echo RUBY_LOCATION=$(which ruby)
echo RUBY_VERSION=$(ruby --version)
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 "hi from a simple admin buildpack"; } | nc -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, "0").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)
})
It("uses a ruby binary for staging", func() {
push := cf.Cf("push", appName,
"-b", BuildpackName,
"-m", DEFAULT_MEMORY_LIMIT,
"-p", appPath,
"-d", Config.GetAppsDomain(),
).Wait(Config.CfPushTimeoutDuration())
Expect(push).To(Exit(0))
Expect(push).To(Say("RUBY_LOCATION=/usr/bin/ruby"))
})
})