forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_test.go
More file actions
157 lines (125 loc) · 4.47 KB
/
init_test.go
File metadata and controls
157 lines (125 loc) · 4.47 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
package integration_test
import (
"flag"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"testing"
"time"
"github.com/onsi/gomega/types"
"github.com/cloudfoundry/switchblade"
"github.com/onsi/gomega/format"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
. "github.com/onsi/gomega"
)
var (
settings struct {
Buildpack struct {
Version string
Path string
}
Cached bool
Serial bool
GitHubToken string
Platform string
Stack string
}
)
func init() {
flag.BoolVar(&settings.Cached, "cached", false, "run cached buildpack tests")
flag.BoolVar(&settings.Serial, "serial", false, "run serial buildpack tests")
flag.StringVar(&settings.Platform, "platform", "cf", `switchblade platform to test against ("cf" or "docker")`)
flag.StringVar(&settings.GitHubToken, "github-token", "", "use the token to make GitHub API requests")
flag.StringVar(&settings.Stack, "stack", "cflinuxfs3", "stack to use when pushing apps")
}
func TestIntegration(t *testing.T) {
var Expect = NewWithT(t).Expect
format.MaxLength = 0
SetDefaultEventuallyTimeout(10 * time.Second)
root, err := filepath.Abs("./../../..")
Expect(err).NotTo(HaveOccurred())
fixtures := filepath.Join(root, "fixtures")
platform, err := switchblade.NewPlatform(settings.Platform, settings.GitHubToken, settings.Stack)
Expect(err).NotTo(HaveOccurred())
goBuildpackFile, err := downloadBuildpack("go")
Expect(err).NotTo(HaveOccurred())
err = platform.Initialize(
switchblade.Buildpack{
Name: "python_buildpack",
URI: os.Getenv("BUILDPACK_FILE"),
},
switchblade.Buildpack{
Name: "override_buildpack",
URI: filepath.Join(fixtures, "util", "override_buildpack"),
},
// Go buildpack is needed for the proxy and the dynatrace apps
switchblade.Buildpack{
Name: "go_buildpack",
URI: goBuildpackFile,
},
)
Expect(err).NotTo(HaveOccurred())
proxyName, err := switchblade.RandomName()
Expect(err).NotTo(HaveOccurred())
proxyDeploymentProcess := platform.Deploy.WithBuildpacks("go_buildpack")
proxyDeployment, _, err := proxyDeploymentProcess.
Execute(proxyName, filepath.Join(fixtures, "util", "proxy"))
Expect(err).NotTo(HaveOccurred())
dynatraceName, err := switchblade.RandomName()
Expect(err).NotTo(HaveOccurred())
dynatraceDeploymentProcess := platform.Deploy.WithBuildpacks("go_buildpack")
dynatraceDeployment, _, err := dynatraceDeploymentProcess.
Execute(dynatraceName, filepath.Join(fixtures, "util", "dynatrace"))
Expect(err).NotTo(HaveOccurred())
suite := spec.New("integration", spec.Report(report.Terminal{}), spec.Parallel())
suite("Default", testDefault(platform, fixtures))
suite("Dynatrace", testDynatrace(platform, fixtures, dynatraceDeployment.InternalURL))
suite("AppDynamics", testAppDynamics(platform, fixtures))
suite("Pip", testPip(platform, fixtures))
suite("Versions", testVersions(platform, fixtures, root))
suite("Miscellaneous", testMiscellaneous(platform, fixtures))
suite("Django", testDjango(platform, fixtures))
suite("Pipenv", testPipenv(platform, fixtures))
suite("Override", testOverride(platform, fixtures))
suite("Multibuildpack", testMultibuildpack(platform, fixtures))
suite("Sealights", testSealights(platform, fixtures))
if settings.Cached {
suite("Offline", testOffline(platform, fixtures))
} else {
suite("Cache", testCache(platform, fixtures))
suite("Proxy", testProxy(platform, fixtures, proxyDeployment.InternalURL))
}
suite.Run(t)
Expect(platform.Delete.Execute(proxyName)).To(Succeed())
Expect(platform.Delete.Execute(dynatraceName)).To(Succeed())
Expect(os.Remove(os.Getenv("BUILDPACK_FILE"))).To(Succeed())
Expect(os.Remove(goBuildpackFile)).To(Succeed())
}
func downloadBuildpack(name string) (string, error) {
uri := fmt.Sprintf("https://github.com/cloudfoundry/%s-buildpack/archive/master.zip", name)
file, err := os.CreateTemp("", fmt.Sprintf("%s-buildpack-*.zip", name))
if err != nil {
return "", err
}
defer file.Close()
resp, err := http.Get(uri)
if err != nil {
return "", err
}
defer resp.Body.Close()
_, err = io.Copy(file, resp.Body)
return file.Name(), err
}
func CreateRequirementsTxtFile(Expect func(actual interface{}, extra ...interface{}) types.Assertion, path string, fileName string, modules ...string) {
file, err := os.Create(filepath.Join(path, fileName))
Expect(err).NotTo(HaveOccurred())
for _, module := range modules {
_, err = file.WriteString(module + "\n")
Expect(err).NotTo(HaveOccurred())
}
err = file.Close()
Expect(err).NotTo(HaveOccurred())
}