forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegration_suite_test.go
More file actions
174 lines (145 loc) · 4.42 KB
/
Copy pathintegration_suite_test.go
File metadata and controls
174 lines (145 loc) · 4.42 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
package integration_test
import (
"encoding/json"
"flag"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
"github.com/cloudfoundry/libbuildpack/cutlass"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
var bpDir string
var buildpackVersion string
var packagedBuildpack cutlass.VersionedBuildpackPackage
func init() {
flag.StringVar(&buildpackVersion, "version", "", "version to use (builds if empty)")
flag.BoolVar(&cutlass.Cached, "cached", true, "cached buildpack")
flag.StringVar(&cutlass.DefaultMemory, "memory", "128M", "default memory for pushed apps")
flag.StringVar(&cutlass.DefaultDisk, "disk", "384M", "default disk for pushed apps")
flag.Parse()
}
var _ = SynchronizedBeforeSuite(func() []byte {
// Run once
if buildpackVersion == "" {
packagedBuildpack, err := cutlass.PackageUniquelyVersionedBuildpack(os.Getenv("CF_STACK"), ApiHasStackAssociation())
Expect(err).NotTo(HaveOccurred())
data, err := json.Marshal(packagedBuildpack)
Expect(err).NotTo(HaveOccurred())
return data
}
return []byte{}
}, func(data []byte) {
// Run on all nodes
var err error
if len(data) > 0 {
err = json.Unmarshal(data, &packagedBuildpack)
Expect(err).NotTo(HaveOccurred())
buildpackVersion = packagedBuildpack.Version
}
bpDir, err = cutlass.FindRoot()
Expect(err).NotTo(HaveOccurred())
Expect(cutlass.CopyCfHome()).To(Succeed())
cutlass.SeedRandom()
cutlass.DefaultStdoutStderr = GinkgoWriter
SetDefaultEventuallyTimeout(10 * time.Second)
})
var _ = SynchronizedAfterSuite(func() {
// Run on all nodes
}, func() {
// Run once
Expect(cutlass.RemovePackagedBuildpack(packagedBuildpack)).To(Succeed())
Expect(cutlass.DeleteOrphanedRoutes()).To(Succeed())
})
func TestIntegration(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Integration Suite")
}
func PushAppAndConfirm(app *cutlass.App) {
Expect(app.Push()).To(Succeed())
Eventually(func() ([]string, error) { return app.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))
Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
}
func Restart(app *cutlass.App) {
Expect(app.Restart()).To(Succeed())
Eventually(func() ([]string, error) { return app.InstanceStates() }, 20*time.Second).Should(Equal([]string{"RUNNING"}))
}
func ApiHasTask() bool {
supported, err := cutlass.ApiGreaterThan("2.75.0")
Expect(err).NotTo(HaveOccurred())
return supported
}
func ApiHasMultiBuildpack() bool {
supported, err := cutlass.ApiGreaterThan("2.90.0")
Expect(err).NotTo(HaveOccurred())
return supported
}
func ApiHasStackAssociation() bool {
supported, err := cutlass.ApiGreaterThan("2.113.0")
Expect(err).NotTo(HaveOccurred())
return supported
}
func AssertUsesProxyDuringStagingIfPresent(fixtureName string) {
Context("with an uncached buildpack", func() {
BeforeEach(func() {
if cutlass.Cached {
Skip("Running cached tests")
}
})
It("uses a proxy during staging if present", func() {
proxy, err := cutlass.NewProxy()
Expect(err).To(BeNil())
defer proxy.Close()
bpFile := filepath.Join(bpDir, buildpackVersion+"tmp")
cmd := exec.Command("cp", packagedBuildpack.File, bpFile)
err = cmd.Run()
Expect(err).To(BeNil())
defer os.Remove(bpFile)
traffic, _, _, err := cutlass.InternetTraffic(
bpDir,
filepath.Join("fixtures", fixtureName),
bpFile,
[]string{"HTTP_PROXY=" + proxy.URL, "HTTPS_PROXY=" + proxy.URL},
)
Expect(err).To(BeNil())
// Expect(built).To(BeTrue())
destUrl, err := url.Parse(proxy.URL)
Expect(err).To(BeNil())
Expect(cutlass.UniqueDestination(
traffic, fmt.Sprintf("%s.%s", destUrl.Hostname(), destUrl.Port()),
)).To(BeNil())
})
})
}
func AssertNoInternetTraffic(fixtureName string) {
It("has no traffic", func() {
if !cutlass.Cached {
Skip("Running uncached tests")
}
bpFile := filepath.Join(bpDir, buildpackVersion+"tmp")
cmd := exec.Command("cp", packagedBuildpack.File, bpFile)
err := cmd.Run()
Expect(err).To(BeNil())
defer os.Remove(bpFile)
traffic, built, logs, err := cutlass.InternetTraffic(
bpDir,
filepath.Join("fixtures", fixtureName),
bpFile,
[]string{"LC_ALL C.UTF-8", "LANG C.UTF-8"},
)
Expect(err).To(BeNil())
Expect(built).To(BeTrue(), strings.Join(logs, "\n"))
Expect(traffic).To(BeEmpty(), strings.Join(logs, "\n"))
})
}
func RunCf(args ...string) error {
command := exec.Command("cf", args...)
command.Stdout = GinkgoWriter
command.Stderr = GinkgoWriter
return command.Run()
}