-
Notifications
You must be signed in to change notification settings - Fork 5
/
pipenv_install_process_test.go
66 lines (53 loc) · 1.86 KB
/
pipenv_install_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
package pipenv_test
import (
"errors"
"fmt"
"os"
"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 testPipenvInstallProcess(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
version = "1.2.3-some.version"
destLayerPath string
executable *fakes.Executable
pipenvInstallProcess pipenv.PipenvInstallProcess
)
it.Before(func() {
destLayerPath = t.TempDir()
executable = &fakes.Executable{}
pipenvInstallProcess = pipenv.NewPipenvInstallProcess(executable)
})
context("Execute", func() {
context("there is a pipenv dependency to install", func() {
it("installs it to the pipenv layer", func() {
err := pipenvInstallProcess.Execute(version, destLayerPath)
Expect(err).NotTo(HaveOccurred())
Expect(executable.ExecuteCall.Receives.Execution.Env).To(Equal(append(os.Environ(), fmt.Sprintf("PYTHONUSERBASE=%s", destLayerPath))))
Expect(executable.ExecuteCall.Receives.Execution.Args).To(Equal([]string{"install", "pipenv==1.2.3-some.version", "--user"}))
})
})
context("failure cases", func() {
context("the install process 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("installing pipenv failed")
}
})
it("returns an error", func() {
err := pipenvInstallProcess.Execute(version, destLayerPath)
Expect(err).To(MatchError(ContainSubstring("installing pipenv failed")))
Expect(err).To(MatchError(ContainSubstring("stdout output")))
Expect(err).To(MatchError(ContainSubstring("stderr output")))
})
})
})
})
}