@@ -23,9 +23,11 @@ var _ = Describe("Sealights", func() {
2323 BeforeEach (func () {
2424 buildDir , err = os .MkdirTemp ("" , "python-buildpack.build." )
2525 Expect (err ).NotTo (HaveOccurred ())
26+ DeferCleanup (os .RemoveAll , buildDir )
2627
2728 depsDir , err = os .MkdirTemp ("" , "python-buildpack.deps." )
2829 Expect (err ).NotTo (HaveOccurred ())
30+ DeferCleanup (os .RemoveAll , depsDir )
2931
3032 buffer = new (bytes.Buffer )
3133 logger := libbuildpack .NewLogger (ansicleaner .New (buffer ))
@@ -37,11 +39,6 @@ var _ = Describe("Sealights", func() {
3739 }
3840 })
3941
40- AfterEach (func () {
41- Expect (os .RemoveAll (buildDir )).To (Succeed ())
42- Expect (os .RemoveAll (depsDir )).To (Succeed ())
43- })
44-
4542 Context ("GenerateStartUpCommand" , func () {
4643 It ("Returns the command when it is provided in the correct format and empty config" , func () {
4744 slConfig := hooks .NewSealightsConfig ()
@@ -97,13 +94,10 @@ var _ = Describe("Sealights", func() {
9794 BeforeEach (func () {
9895 tempProcDir , err = os .MkdirTemp ("" , "Procfiles" )
9996 Expect (err ).NotTo (HaveOccurred ())
97+ DeferCleanup (os .RemoveAll , tempProcDir )
10098 slConfig = hooks .NewSealightsConfig ()
10199 })
102100
103- AfterEach (func () {
104- Expect (os .RemoveAll (tempProcDir )).To (Succeed ())
105- })
106-
107101 It ("rewrites the procfile with sl-python" , func () {
108102 Expect (os .WriteFile (filepath .Join (tempProcDir , "Procfile" ), []byte ("web: python app.py" ), 0666 )).To (Succeed ())
109103 Expect (err ).NotTo (HaveOccurred ())
@@ -144,9 +138,7 @@ var _ = Describe("Sealights", func() {
144138 requirementsFilepath := filepath .Join (buildDir , "requirements.txt" )
145139 Expect (libbuildpack .FileExists (requirementsFilepath )).ToNot (BeTrue ())
146140 Expect (os .WriteFile (requirementsFilepath , []byte ("Flask" ), 0644 )).To (Succeed ())
147- })
148- AfterEach (func () {
149- Expect (os .Remove (filepath .Join (buildDir , "requirements.txt" ))).To (Succeed ())
141+ DeferCleanup (os .Remove , filepath .Join (buildDir , "requirements.txt" ))
150142 })
151143
152144 It ("Rewrites requirements.txt" , func () {
@@ -169,10 +161,7 @@ var _ = Describe("Sealights", func() {
169161 Expect (os .Getenv ("VCAP_SERVICES" )).To (Equal ("" ))
170162 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("web: python app.py" ), 0644 )).To (Succeed ())
171163 Expect (err ).NotTo (HaveOccurred ())
172- })
173-
174- AfterEach (func () {
175- Expect (os .Remove (filepath .Join (buildDir , "Procfile" ))).To (Succeed ())
164+ DeferCleanup (os .Remove , filepath .Join (buildDir , "Procfile" ))
176165 })
177166
178167 It ("BeforeCompile does not modify the existing Procfile" , func () {
@@ -190,11 +179,8 @@ var _ = Describe("Sealights", func() {
190179 os .Setenv ("VCAP_SERVICES" , `{"service": [{"credentials": {"login": "name"}, "name": "443"}]}` )
191180 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("web: python app.py" ), 0644 )).To (Succeed ())
192181 Expect (err ).NotTo (HaveOccurred ())
193- })
194-
195- AfterEach (func () {
196- Expect (os .Remove (filepath .Join (buildDir , "Procfile" ))).To (Succeed ())
197- os .Unsetenv ("VCAP_SERVICES" )
182+ DeferCleanup (os .Remove , filepath .Join (buildDir , "Procfile" ))
183+ DeferCleanup (os .Unsetenv , "VCAP_SERVICES" )
198184 })
199185
200186 It ("BeforeCompile does not modify the existing Procfile" , func () {
@@ -212,11 +198,8 @@ var _ = Describe("Sealights", func() {
212198 os .Setenv ("VCAP_SERVICES" , `{"sealights":[{"credentials":{"token":"","tokenFile":"token.txt"}}]}` )
213199 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("web: python app.py" ), 0644 )).To (Succeed ())
214200 Expect (err ).NotTo (HaveOccurred ())
215- })
216-
217- AfterEach (func () {
218- os .Unsetenv ("VCAP_SERVICES" )
219- os .Unsetenv ("SL_TOKEN" )
201+ DeferCleanup (os .Unsetenv , "VCAP_SERVICES" )
202+ DeferCleanup (os .Unsetenv , "SL_TOKEN" )
220203 })
221204 It ("BeforeCompile modify the existing Procfile" , func () {
222205 err := sealights .BeforeCompile (stager )
@@ -252,10 +235,7 @@ var _ = Describe("Sealights", func() {
252235 os .Setenv ("VCAP_SERVICES" , `{"some-sealights":[{"credentials":{"token":"","tokenFile":"token.txt"}}]}` )
253236 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("web: python app.py" ), 0644 )).To (Succeed ())
254237 Expect (err ).NotTo (HaveOccurred ())
255- })
256-
257- AfterEach (func () {
258- os .Unsetenv ("VCAP_SERVICES" )
238+ DeferCleanup (os .Unsetenv , "VCAP_SERVICES" )
259239 })
260240 It ("BeforeCompile modify the existing Procfile" , func () {
261241 err := sealights .BeforeCompile (stager )
@@ -276,10 +256,7 @@ var _ = Describe("Sealights", func() {
276256 os .Setenv ("VCAP_SERVICES" , `{"user-provided":[{"binding_guid":"af3fea1b-8beb-4397-968e-6440d2906551","binding_name":null,"credentials":{"token":"","tokenFile":"sltoken.txt"},"instance_guid":"d5c36671-dc09-4cd9-8697-70adc0c0f6e9","instance_name":"sealights","label":"user-provided","name":"sealights","syslog_drain_url":null,"tags":[],"volume_mounts":[]}]}` )
277257 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("web: python app.py" ), 0644 )).To (Succeed ())
278258 Expect (err ).NotTo (HaveOccurred ())
279- })
280-
281- AfterEach (func () {
282- os .Unsetenv ("VCAP_SERVICES" )
259+ DeferCleanup (os .Unsetenv , "VCAP_SERVICES" )
283260 })
284261 It ("BeforeCompile modify the existing Procfile" , func () {
285262 err := sealights .BeforeCompile (stager )
@@ -300,10 +277,7 @@ var _ = Describe("Sealights", func() {
300277 os .Setenv ("VCAP_SERVICES" , `{"sealights":[{"credentials":{"token":"","tokenFile":"token.txt"}}]}` )
301278 Expect (os .WriteFile (filepath .Join (buildDir , "Procfile" ), []byte ("python app.py" ), 0644 )).To (Succeed ())
302279 Expect (err ).NotTo (HaveOccurred ())
303- })
304-
305- AfterEach (func () {
306- os .Unsetenv ("VCAP_SERVICES" )
280+ DeferCleanup (os .Unsetenv , "VCAP_SERVICES" )
307281 })
308282 It ("BeforeCompile is not modify the existing Procfile - bad format" , func () {
309283 err := sealights .BeforeCompile (stager )
0 commit comments