forked from cloudfoundry/cf-acceptance-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpack_cache.go
146 lines (117 loc) · 3.84 KB
/
buildpack_cache.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
package apps
import (
"fmt"
"io/ioutil"
"os"
"path"
"time"
. "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/helpers"
"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 cache", func() {
var (
appName string
BuildpackName string
appPath string
buildpackPath string
buildpackArchivePath string
)
matchingFilename := func(appName string) string {
return fmt.Sprintf("buildpack-for-buildpack-cache-test-%s", appName)
}
BeforeEach(func() {
workflowhelpers.AsUser(TestSetup.AdminUserContext(), Config.DefaultTimeoutDuration(), func() {
BuildpackName = CATSRandomName("BPK")
appName = CATSRandomName("APP")
tmpdir, err := ioutil.TempDir(os.TempDir(), "matching-app")
Expect(err).ToNot(HaveOccurred())
appPath = tmpdir
tmpdir, err = ioutil.TempDir(os.TempDir(), "matching-buildpack")
Expect(err).ToNot(HaveOccurred())
buildpackPath = tmpdir
buildpackArchivePath = path.Join(buildpackPath, "buildpack.zip")
archive_helpers.CreateZipArchive(buildpackArchivePath, []archive_helpers.ArchiveFile{
{
Name: "bin/compile",
Body: `#!/usr/bin/env bash
mkdir -p $1 $2
if [ -f "$2/cached-file" ]; then
cp $2/cached-file $1/content
else
echo "cache not found" > $1/content
fi
echo "here's a cache" > $2/cached-file
`,
},
{
Name: "bin/detect",
Body: fmt.Sprintf(`#!/bin/bash
if [ -f "${1}/%s" ]; then
echo Buildpack that needs cache
else
echo no
exit 1
fi
`, matchingFilename(appName)),
},
{
Name: "bin/release",
Body: `#!/usr/bin/env bash
content=$(cat $1/content)
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 "custom buildpack contents - $content"; } | 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, "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))
})
})
It("uses the buildpack cache after first staging", func() {
Expect(cf.Cf("push", appName,
"-b", BuildpackName,
"-m", DEFAULT_MEMORY_LIMIT,
"-p", appPath,
"-d", Config.GetAppsDomain(),
).Wait(Config.CfPushTimeoutDuration())).To(Exit(0))
Eventually(func() string {
return helpers.CurlAppRoot(Config, appName)
}).Should(ContainSubstring("custom buildpack contents - cache not found"))
time.Sleep(Config.SleepTimeoutDuration())
restage := cf.Cf("restage", appName).Wait(Config.CfPushTimeoutDuration())
Expect(restage).To(Exit(0))
Eventually(func() string {
return helpers.CurlAppRoot(Config, appName)
}).Should(ContainSubstring("custom buildpack contents - here's a cache"))
})
})