-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpoetry_install_process_test.go
70 lines (56 loc) · 1.96 KB
/
poetry_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
67
68
69
70
package poetry_test
import (
"errors"
"fmt"
"os"
"testing"
"github.com/paketo-buildpacks/packit/v2/pexec"
"github.com/paketo-buildpacks/poetry"
"github.com/paketo-buildpacks/poetry/fakes"
"github.com/sclevine/spec"
. "github.com/onsi/gomega"
)
func testPoetryInstallProcess(t *testing.T, context spec.G, it spec.S) {
var (
Expect = NewWithT(t).Expect
version string
destLayerPath string
executable *fakes.Executable
poetryInstallProcess poetry.PoetryInstallProcess
)
it.Before(func() {
var err error
destLayerPath, err = os.MkdirTemp("", "poetry")
Expect(err).NotTo(HaveOccurred())
version = "1.2.3-some.version"
executable = &fakes.Executable{}
poetryInstallProcess = poetry.NewPoetryInstallProcess(executable)
})
context("Execute", func() {
context("there is a poetry dependency to install", func() {
it("installs it to the poetry layer", func() {
err := poetryInstallProcess.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{"-m", "pip", "install", "poetry==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 poetry failed")
}
})
it("returns an error", func() {
err := poetryInstallProcess.Execute(version, destLayerPath)
Expect(err).To(MatchError(ContainSubstring("installing poetry failed")))
Expect(err).To(MatchError(ContainSubstring("stdout output")))
Expect(err).To(MatchError(ContainSubstring("stderr output")))
})
})
})
})
}