forked from cloudfoundry/python-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpip_test.go
More file actions
211 lines (168 loc) · 6.14 KB
/
pip_test.go
File metadata and controls
211 lines (168 loc) · 6.14 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package integration_test
import (
"os"
"path/filepath"
"testing"
"github.com/cloudfoundry/switchblade"
"github.com/sclevine/spec"
. "github.com/cloudfoundry/switchblade/matchers"
. "github.com/onsi/gomega"
)
func testPip(platform switchblade.Platform, fixtures string) func(*testing.T, spec.G, spec.S) {
return func(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
Eventually = NewWithT(t).Eventually
name string
source string
)
it.Before(func() {
var err error
name, err = switchblade.RandomName()
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(platform.Delete.Execute(name)).To(Succeed())
})
context("when there is a requirements.txt file", func() {
context("when using modifiers in requirements.txt", func() {
context("using editable mode (-e)", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "simple"))
Expect(err).NotTo(HaveOccurred())
file, err := os.OpenFile(filepath.Join(source, "requirements.txt"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600)
Expect(err).NotTo(HaveOccurred())
Expect(err).NotTo(HaveOccurred())
Expect(file.Close()).To(Succeed())
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("handles recursive requirements successfully", func() {
deployment, logs, err := platform.Deploy.
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Hello, World!"))
Expect(logs.String()).To(SatisfyAll(
ContainSubstring("Running Pip Install (Unvendored)"),
ContainSubstring("Cloning https://github.com/eregs/regulations-core.git"),
))
})
})
context("using recursive mode (-r)", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "simple"))
Expect(err).NotTo(HaveOccurred())
Expect(os.Remove(filepath.Join(source, "requirements.txt"))).To(Succeed())
err = os.Mkdir(filepath.Join(source, "sub_folder"), 0755)
Expect(err).NotTo(HaveOccurred())
CreateRequirementsTxtFile(Expect, filepath.Join(source, "sub_folder"), "other_requirement1.txt", "Markupsafe", "-r other_requirement2.txt")
CreateRequirementsTxtFile(Expect, filepath.Join(source, "sub_folder"), "other_requirement2.txt", "Werkzeug")
CreateRequirementsTxtFile(Expect, source, "requirements.txt", "Flask", "Jinja2", "gunicorn", "itsdangerous", "pylibmc", "cffi", "-r sub_folder/other_requirement1.txt")
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("installs the regulations-core package", func() {
deployment, logs, err := platform.Deploy.
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Hello, World!"))
Expect(logs.String()).To(SatisfyAll(
ContainSubstring("Collecting Markupsafe"),
ContainSubstring("Collecting Werkzeug"),
))
})
})
})
context("when specifying pip version", func() {
context("when using default version", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "simple"))
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("uses python's pip module", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{"BP_PIP_VERSION": ""}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Hello, World!"))
Expect(logs.String()).To(SatisfyAll(
ContainSubstring("Using python's pip module"),
))
})
})
context("when using latest version", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "simple"))
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("uses latest from manifest", func() {
deployment, logs, err := platform.Deploy.
WithEnv(map[string]string{"BP_PIP_VERSION": "latest"}).
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Hello, World!"))
Expect(logs.String()).To(SatisfyAll(
ContainSubstring("Installing pip"),
MatchRegexp(`Successfully installed pip-\d+.\d+(.\d+)?`),
))
})
})
})
})
context("when there is no requirements.txt file", func() {
context("when there is a setup.py file", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "setup_py"))
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("successfully deploys", func() {
deployment, logs, err := platform.Deploy.
WithBuildpacks("python_buildpack").
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Knock Knock. Who is there?"))
Expect(logs.String()).To(SatisfyAll(
Not(ContainSubstring("Skipping 'pip install' since requirements.txt does not exist")),
))
})
})
context("when there is no setup.py file", func() {
it.Before(func() {
var err error
source, err = switchblade.Source(filepath.Join(fixtures, "no_deps"))
Expect(err).NotTo(HaveOccurred())
})
it.After(func() {
Expect(os.RemoveAll(source)).To(Succeed())
})
it("successfully deploys", func() {
deployment, logs, err := platform.Deploy.
WithBuildpacks("python_buildpack").
Execute(name, source)
Expect(err).NotTo(HaveOccurred())
Eventually(deployment).Should(Serve("Here is your output for /"))
Expect(logs.String()).To(SatisfyAll(
Not(ContainSubstring("Skipping 'pip install' since requirements.txt does not exist")),
))
})
})
})
}
}