-
Notifications
You must be signed in to change notification settings - Fork 17
/
build_test.go
623 lines (518 loc) · 20.9 KB
/
build_test.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
package cpython_test
import (
"bytes"
"errors"
"os"
"path/filepath"
"testing"
"github.com/paketo-buildpacks/cpython"
"github.com/paketo-buildpacks/cpython/fakes"
"github.com/paketo-buildpacks/packit/v2"
"github.com/paketo-buildpacks/packit/v2/chronos"
//nolint Ignore SA1019, informed usage of deprecated package
"github.com/paketo-buildpacks/packit/v2/paketosbom"
"github.com/paketo-buildpacks/packit/v2/postal"
"github.com/paketo-buildpacks/packit/v2/sbom"
"github.com/paketo-buildpacks/packit/v2/scribe"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testBuild(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
layersDir string
cnbDir string
clock chronos.Clock
dependencyManager *fakes.DependencyManager
pythonInstaller *fakes.PythonInstaller
pipCleanup *fakes.PythonPipCleanup
sbomGenerator *fakes.SBOMGenerator
buffer *bytes.Buffer
logEmitter scribe.Emitter
build packit.BuildFunc
buildContext packit.BuildContext
)
it.Before(func() {
var err error
layersDir, err = os.MkdirTemp("", "layers")
Expect(err).NotTo(HaveOccurred())
cnbDir, err = os.MkdirTemp("", "cnb")
Expect(err).NotTo(HaveOccurred())
clock = chronos.DefaultClock
dependencyManager = &fakes.DependencyManager{}
dependencyManager.ResolveCall.Returns.Dependency = postal.Dependency{
// Dependecy is called python not cpython
ID: "python",
Name: "python-dependency-name",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Version: "python-dependency-version",
}
// Legacy SBOM
dependencyManager.GenerateBillOfMaterialsCall.Returns.BOMEntrySlice = []packit.BOMEntry{
{
Name: "cpython",
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "cpython-dependency-sha",
},
URI: "cpython-dependency-uri",
Version: "cpython-dependency-version",
},
},
}
dependencyManager.DeliverCall.Stub = func(_ postal.Dependency, _ string, destinationPath string, _ string) error {
Expect(os.MkdirAll(filepath.Join(destinationPath, "bin"), os.ModePerm)).To(Succeed())
Expect(os.WriteFile(filepath.Join(destinationPath, "bin", "python"), []byte{}, os.ModePerm)).To(Succeed())
Expect(os.WriteFile(filepath.Join(destinationPath, "bin", "python3"), []byte{}, os.ModePerm)).To(Succeed())
return nil
}
// Syft SBOM
sbomGenerator = &fakes.SBOMGenerator{}
sbomGenerator.GenerateFromDependencyCall.Returns.SBOM = sbom.SBOM{}
buffer = bytes.NewBuffer(nil)
logEmitter = scribe.NewEmitter(buffer).WithLevel("DEBUG")
buildContext = packit.BuildContext{
BuildpackInfo: packit.BuildpackInfo{
Name: "cpython",
Version: "some-version",
SBOMFormats: []string{sbom.CycloneDXFormat, sbom.SPDXFormat},
},
CNBPath: cnbDir,
Plan: packit.BuildpackPlan{
Entries: []packit.BuildpackPlanEntry{
{Name: "cpython"},
},
},
Platform: packit.Platform{Path: "platform"},
Layers: packit.Layers{Path: layersDir},
Stack: "some-stack",
}
pythonInstaller = &fakes.PythonInstaller{}
pipCleanup = &fakes.PythonPipCleanup{}
build = cpython.Build(dependencyManager, pythonInstaller, pipCleanup, sbomGenerator, logEmitter, clock)
})
it.After(func() {
Expect(os.RemoveAll(layersDir)).To(Succeed())
Expect(os.RemoveAll(cnbDir)).To(Succeed())
})
it("returns a result that installs python", func() {
result, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(result.Layers).To(HaveLen(1))
layer := result.Layers[0]
Expect(layer.Name).To(Equal("cpython"))
Expect(layer.Path).To(Equal(filepath.Join(layersDir, "cpython")))
Expect(layer.BuildEnv).To(Equal(packit.Environment{
"PYTHONPYCACHEPREFIX.default": "/tmp",
}))
Expect(layer.SharedEnv).To(Equal(packit.Environment{
"PYTHONPATH.default": filepath.Join(layersDir, "cpython"),
}))
Expect(layer.LaunchEnv).To(BeEmpty())
Expect(layer.ProcessLaunchEnv).To(BeEmpty())
Expect(layer.Build).To(BeFalse())
Expect(layer.Launch).To(BeFalse())
Expect(layer.Cache).To(BeFalse())
Expect(layer.Metadata).To(Equal(map[string]interface{}{
"dependency-sha": "python-dependency-sha",
}))
Expect(layer.ExecD).To(Equal([]string{
filepath.Join(cnbDir, "bin", "env"),
}))
Expect(layer.SBOM.Formats()).To(HaveLen(2))
var actualExtensions []string
for _, format := range layer.SBOM.Formats() {
actualExtensions = append(actualExtensions, format.Extension)
}
Expect(actualExtensions).To(ConsistOf("cdx.json", "spdx.json"))
Expect(dependencyManager.ResolveCall.Receives.Path).To(Equal(filepath.Join(cnbDir, "buildpack.toml")))
// Dependecy is called python not cpython
Expect(dependencyManager.ResolveCall.Receives.Id).To(Equal("python"))
Expect(dependencyManager.ResolveCall.Receives.Version).To(Equal(""))
Expect(dependencyManager.ResolveCall.Receives.Stack).To(Equal("some-stack"))
Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Version: "python-dependency-version",
}))
Expect(dependencyManager.DeliverCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.DeliverCall.Receives.DestinationPath).To(Equal(filepath.Join(layersDir, "cpython")))
Expect(dependencyManager.DeliverCall.Receives.PlatformPath).To(Equal("platform"))
Expect(dependencyManager.GenerateBillOfMaterialsCall.Receives.Dependencies).To(Equal([]postal.Dependency{
{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Version: "python-dependency-version",
},
}))
Expect(sbomGenerator.GenerateFromDependencyCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Version: "python-dependency-version",
}))
Expect(sbomGenerator.GenerateFromDependencyCall.Receives.Dir).To(Equal(filepath.Join(layersDir, "cpython")))
Expect(buffer.String()).To(ContainSubstring("cpython some-version"))
Expect(buffer.String()).To(ContainSubstring("Resolving CPython version"))
Expect(buffer.String()).To(ContainSubstring("Selected CPython version (using <unknown>): python-dependency-version"))
Expect(buffer.String()).To(ContainSubstring("Executing build process"))
Expect(buffer.String()).To(ContainSubstring("Installing CPython python-dependency-version"))
Expect(buffer.String()).To(ContainSubstring("Completed in"))
// Pre-compiled binary installation does not call pythonInstaller.Install
Expect(pythonInstaller.InstallCall.CallCount).To(Equal(0))
Expect(pipCleanup.CleanupCall.CallCount).To(Equal(0))
})
it("returns a result that compiles and installs python from source", func() {
// Let the build function know to install from source
dependencyManager.ResolveCall.Returns.Dependency.Source = dependencyManager.ResolveCall.Returns.Dependency.URI
// Dependency manager only delivers source to python-source directory in layersDir
dependencyManager.DeliverCall.Returns.Error = nil
pythonInstaller.InstallCall.Stub = func(_ string, _ string, _ packit.BuildpackPlanEntry, _ postal.Dependency, destinationPath string) error {
Expect(os.MkdirAll(filepath.Join(destinationPath, "bin"), os.ModePerm)).To(Succeed())
Expect(os.WriteFile(filepath.Join(destinationPath, "bin", "python3"), []byte{}, os.ModePerm)).To(Succeed())
return nil
}
result, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(pythonInstaller.InstallCall.CallCount).To(Equal(1))
Expect(pipCleanup.CleanupCall.CallCount).To(Equal(0))
Expect(result.Layers).To(HaveLen(1))
layer := result.Layers[0]
Expect(layer.Name).To(Equal("cpython"))
Expect(layer.Path).To(Equal(filepath.Join(layersDir, "cpython")))
Expect(layer.BuildEnv).To(Equal(packit.Environment{
"PYTHONPYCACHEPREFIX.default": "/tmp",
}))
Expect(layer.SharedEnv).To(Equal(packit.Environment{
"PYTHONPATH.default": filepath.Join(layersDir, "cpython"),
}))
Expect(layer.LaunchEnv).To(BeEmpty())
Expect(layer.ProcessLaunchEnv).To(BeEmpty())
Expect(layer.Build).To(BeFalse())
Expect(layer.Launch).To(BeFalse())
Expect(layer.Cache).To(BeFalse())
Expect(layer.Metadata).To(Equal(map[string]interface{}{
"dependency-sha": "python-dependency-sha",
}))
Expect(layer.ExecD).To(Equal([]string{
filepath.Join(cnbDir, "bin", "env"),
}))
Expect(layer.SBOM.Formats()).To(HaveLen(2))
var actualExtensions []string
for _, format := range layer.SBOM.Formats() {
actualExtensions = append(actualExtensions, format.Extension)
}
Expect(actualExtensions).To(ConsistOf("cdx.json", "spdx.json"))
Expect(dependencyManager.ResolveCall.Receives.Path).To(Equal(filepath.Join(cnbDir, "buildpack.toml")))
// Dependecy is called python not cpython
Expect(dependencyManager.ResolveCall.Receives.Id).To(Equal("python"))
Expect(dependencyManager.ResolveCall.Receives.Version).To(Equal(""))
Expect(dependencyManager.ResolveCall.Receives.Stack).To(Equal("some-stack"))
Expect(dependencyManager.DeliverCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Source: "python-dependency-uri",
Version: "python-dependency-version",
StripComponents: 1,
}))
Expect(dependencyManager.DeliverCall.Receives.CnbPath).To(Equal(cnbDir))
Expect(dependencyManager.DeliverCall.Receives.DestinationPath).To(Equal(filepath.Join(layersDir, "cpython/python-source")))
Expect(dependencyManager.DeliverCall.Receives.PlatformPath).To(Equal("platform"))
Expect(dependencyManager.GenerateBillOfMaterialsCall.Receives.Dependencies).To(Equal([]postal.Dependency{
{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Source: "python-dependency-uri",
Version: "python-dependency-version",
},
}))
Expect(sbomGenerator.GenerateFromDependencyCall.Receives.Dependency).To(Equal(postal.Dependency{
ID: "cpython",
Name: "CPython",
Checksum: "python-dependency-sha",
Stacks: []string{"some-stack"},
URI: "python-dependency-uri",
Source: "python-dependency-uri",
Version: "python-dependency-version",
StripComponents: 1,
}))
Expect(sbomGenerator.GenerateFromDependencyCall.Receives.Dir).To(Equal(filepath.Join(layersDir, "cpython")))
Expect(buffer.String()).To(ContainSubstring("cpython some-version"))
Expect(buffer.String()).To(ContainSubstring("Resolving CPython version"))
Expect(buffer.String()).To(ContainSubstring("Selected CPython version (using <unknown>): python-dependency-version"))
Expect(buffer.String()).To(ContainSubstring("Executing build process"))
Expect(buffer.String()).To(ContainSubstring("Installing CPython python-dependency-version"))
Expect(buffer.String()).To(ContainSubstring("Completed in"))
})
context("when the plan entry requires the dependency during the build and launch phases", func() {
it.Before(func() {
buildContext.Plan.Entries[0].Metadata = map[string]interface{}{"build": true, "launch": true}
})
it("makes the layer available in those phases", func() {
result, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(result.Layers).To(HaveLen(1))
layer := result.Layers[0]
Expect(layer.Name).To(Equal("cpython"))
Expect(layer.Build).To(BeTrue())
Expect(layer.Launch).To(BeTrue())
Expect(layer.Cache).To(BeTrue())
Expect(result.Build.BOM).To(Equal(
[]packit.BOMEntry{
{
Name: "cpython",
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "cpython-dependency-sha",
},
URI: "cpython-dependency-uri",
Version: "cpython-dependency-version",
},
},
},
))
Expect(result.Launch.BOM).To(Equal(
[]packit.BOMEntry{
{
Name: "cpython",
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "cpython-dependency-sha",
},
URI: "cpython-dependency-uri",
Version: "cpython-dependency-version",
},
},
},
))
})
})
context("when the cached SHA matches the dependency SHA", func() {
it.Before(func() {
err := os.WriteFile(filepath.Join(layersDir, "cpython.toml"), []byte("[metadata]\ndependency-sha = \"python-dependency-sha\"\n"), 0600)
Expect(err).NotTo(HaveOccurred())
buildContext.Plan.Entries[0].Metadata = map[string]interface{}{"build": true}
})
it("reuses the existing layer", func() {
result, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(result.Layers).To(HaveLen(1))
layer := result.Layers[0]
Expect(layer.Name).To(Equal("cpython"))
Expect(layer.Build).To(BeTrue())
Expect(layer.Launch).To(BeFalse())
Expect(layer.Cache).To(BeTrue())
Expect(result.Build.BOM).To(Equal(
[]packit.BOMEntry{
{
Name: "cpython",
Metadata: paketosbom.BOMMetadata{
Checksum: paketosbom.BOMChecksum{
Algorithm: paketosbom.SHA256,
Hash: "cpython-dependency-sha",
},
URI: "cpython-dependency-uri",
Version: "cpython-dependency-version",
},
},
},
))
Expect(dependencyManager.DeliverCall.CallCount).To(Equal(0))
Expect(sbomGenerator.GenerateFromDependencyCall.CallCount).To(Equal(0))
})
})
context("ensures that 'bin/python' exists", func() {
context("when bin/python does not already exist", func() {
it.Before(func() {
dependencyManager.DeliverCall.Stub = func(_ postal.Dependency, _ string, destinationPath string, _ string) error {
Expect(os.MkdirAll(filepath.Join(destinationPath, "bin"), os.ModePerm)).To(Succeed())
Expect(os.WriteFile(filepath.Join(destinationPath, "bin", "python3"), []byte{}, os.ModePerm)).To(Succeed())
return nil
}
})
it("will add a 'bin/python => bin/python3' symlink", func() {
_, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(filepath.Join(layersDir, "cpython", "bin", "python")).To(BeARegularFile())
Expect(buffer.String()).To(ContainSubstring("Writing symlink bin/python"))
symlink, err := filepath.EvalSymlinks(filepath.Join(layersDir, "cpython", "bin", "python"))
Expect(err).NotTo(HaveOccurred())
expectedPath, err := filepath.EvalSymlinks(filepath.Join(layersDir, "cpython", "bin", "python3"))
Expect(err).NotTo(HaveOccurred())
Expect(symlink).To(Equal(expectedPath))
})
})
context("when bin/python already exists", func() {
it("will not add a symlink", func() {
_, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(filepath.Join(layersDir, "cpython", "bin", "python")).To(BeARegularFile())
Expect(buffer.String()).To(ContainSubstring("bin/python already exists"))
})
})
})
context("when the BP_CPYTHON_RM_SETUPTOOLS env var is set", func() {
it.Before(func() {
t.Setenv("BP_CPYTHON_RM_SETUPTOOLS", "value-is-ignored")
})
it("pip cleanup is called", func() {
_, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(pipCleanup.CleanupCall.CallCount).To(Equal(1))
})
})
context("when the BP_CPYTHON_RM_SETUPTOOLS env var is not set", func() {
it("pip cleanup is not called", func() {
_, err := build(buildContext)
Expect(err).NotTo(HaveOccurred())
Expect(pipCleanup.CleanupCall.CallCount).To(Equal(0))
})
})
context("failure cases", func() {
context("when the dependency cannot be resolved", func() {
it.Before(func() {
dependencyManager.ResolveCall.Returns.Error = errors.New("failed to resolve dependency")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError("failed to resolve dependency"))
})
})
context("when generating the SBOM returns an error", func() {
it.Before(func() {
buildContext.BuildpackInfo.SBOMFormats = []string{"random-format"}
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError(`unsupported SBOM format: 'random-format'`))
})
})
context("when formatting the SBOM returns an error", func() {
it.Before(func() {
sbomGenerator.GenerateFromDependencyCall.Returns.Error = errors.New("failed to generate SBOM")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError(ContainSubstring("failed to generate SBOM")))
})
})
context("when the python layer cannot be retrieved", func() {
it.Before(func() {
err := os.WriteFile(filepath.Join(layersDir, "cpython.toml"), nil, 0000)
Expect(err).NotTo(HaveOccurred())
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError(ContainSubstring("failed to parse layer content metadata")))
})
})
context("when the python layer cannot be reset", func() {
it.Before(func() {
Expect(os.MkdirAll(filepath.Join(layersDir, "cpython", "something"), os.ModePerm)).To(Succeed())
Expect(os.Chmod(filepath.Join(layersDir, "cpython"), 0500)).To(Succeed())
})
it.After(func() {
Expect(os.Chmod(filepath.Join(layersDir, "cpython"), os.ModePerm)).To(Succeed())
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError(ContainSubstring("could not remove file")))
})
})
context("when the dependency cannot be installed", func() {
it.Before(func() {
dependencyManager.DeliverCall.Stub = nil
dependencyManager.DeliverCall.Returns.Error = errors.New("failed to install dependency")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError("failed to install dependency"))
})
})
context("when the BP_CPYTHON_RM_SETUPTOOLS env var is set", func() {
it.Before(func() {
t.Setenv("BP_CPYTHON_RM_SETUPTOOLS", "value-is-ignored")
})
context("pip cleanup call fails with error", func() {
it.Before(func() {
pipCleanup.CleanupCall.Returns.Error = errors.New("failed to uninstall pip package")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(pipCleanup.CleanupCall.CallCount).To(Equal(1))
Expect(err).To(MatchError("failed to uninstall pip package"))
})
})
})
context("installing python from source", func() {
it.Before(func() {
dependencyManager.ResolveCall.Returns.Dependency.Source = dependencyManager.ResolveCall.Returns.Dependency.URI
dependencyManager.DeliverCall.Stub = nil
dependencyManager.DeliverCall.Returns.Error = nil
pythonInstaller.InstallCall.Stub = func(_ string, _ string, _ packit.BuildpackPlanEntry, _ postal.Dependency, destinationPath string) error {
Expect(os.MkdirAll(filepath.Join(destinationPath, "bin"), os.ModePerm)).To(Succeed())
Expect(os.WriteFile(filepath.Join(destinationPath, "bin", "python3"), []byte{}, os.ModePerm)).To(Succeed())
return nil
}
})
context("delivering the source dependency fails with error", func() {
it.Before(func() {
dependencyManager.DeliverCall.Returns.Error = errors.New("failed to download source dependency")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError("failed to download source dependency"))
})
})
context("removing source path directory fails with error", func() {
var pythonSourcePath string
var testFilePath string
it.Before(func() {
pythonInstaller.InstallCall.Stub = func(sourcePath string, _ string, _ packit.BuildpackPlanEntry, _ postal.Dependency, destinationPath string) error {
pythonSourcePath = sourcePath
testFilePath = filepath.Join(sourcePath, "some-file")
Expect(os.WriteFile(testFilePath, []byte{}, os.ModePerm)).To(Succeed())
Expect(os.Chmod(sourcePath, 0500)).NotTo(HaveOccurred())
return nil
}
})
it.After(func() {
Expect(os.Chmod(pythonSourcePath, os.ModePerm)).NotTo(HaveOccurred())
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError(ContainSubstring(testFilePath + ": permission denied")))
})
})
context("when the installation process fails with error", func() {
it.Before(func() {
pythonInstaller.InstallCall.Stub = nil
pythonInstaller.InstallCall.Returns.Error = errors.New("failed to install python")
})
it("returns an error", func() {
_, err := build(buildContext)
Expect(err).To(MatchError("failed to install python"))
})
})
})
})
}