-
Notifications
You must be signed in to change notification settings - Fork 5
/
site_process_test.go
74 lines (60 loc) · 2.13 KB
/
site_process_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
package pipenv_test
import (
"errors"
"fmt"
"os"
"path/filepath"
"testing"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/pipenv"
"github.com/paketo-buildpacks/pipenv/fakes"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testSiteProcess(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
targetLayerPath string
executable *fakes.Executable
siteProcess pipenv.SiteProcess
)
it.Before(func() {
targetLayerPath = t.TempDir()
executable = &fakes.Executable{}
executable.ExecuteCall.Stub = func(execution pexec.Execution) error {
if execution.Stdout != nil {
fmt.Fprint(execution.Stdout, targetLayerPath, "/pipenv/lib/python/site-packages")
}
return nil
}
siteProcess = pipenv.NewSiteProcess(executable)
})
context("Execute", func() {
context("there are site packages in the pipenv layer", func() {
it("returns the full path to the packages", func() {
sitePackagesPath, err := siteProcess.Execute(targetLayerPath)
Expect(err).NotTo(HaveOccurred())
Expect(executable.ExecuteCall.Receives.Execution.Env).To(Equal(append(os.Environ(), fmt.Sprintf("PYTHONUSERBASE=%s", targetLayerPath))))
Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{"-m", "site", "--user-site"}))
Expect(sitePackagesPath).To(Equal(filepath.Join(targetLayerPath, "pipenv", "lib", "python", "site-packages")))
})
})
context("failure cases", func() {
context("site package lookup fails", func() {
it.Before(func() {
executable.ExecuteCall.Stub = func(execution pexec.Execution) error {
fmt.Fprintln(execution.Stdout, "stdout output")
fmt.Fprintln(execution.Stderr, "stderr output")
return errors.New("locating site packages failed")
}
})
it("returns an error", func() {
_, err := siteProcess.Execute(targetLayerPath)
Expect(err).To(MatchError(ContainSubstring("failed to locate site packages:")))
Expect(err).To(MatchError(ContainSubstring("stderr output")))
Expect(err).To(MatchError(ContainSubstring("error: locating site packages failed")))
})
})
})
})
}