-
Notifications
You must be signed in to change notification settings - Fork 4
/
pull_test.go
87 lines (71 loc) · 1.92 KB
/
pull_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
package groot_test
import (
"bytes"
"io"
"code.cloudfoundry.org/groot"
"code.cloudfoundry.org/groot/grootfakes"
"code.cloudfoundry.org/groot/imagepuller"
"code.cloudfoundry.org/lager/v3"
"code.cloudfoundry.org/lager/v3/lagertest"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
errors "github.com/pkg/errors"
)
var _ = Describe("Pull", func() {
var (
imagePuller *grootfakes.FakeImagePuller
driver *grootfakes.FakeDriver
logger *lagertest.TestLogger
g *groot.Groot
)
BeforeEach(func() {
imagePuller = new(grootfakes.FakeImagePuller)
driver = new(grootfakes.FakeDriver)
imagePuller.PullReturns(imagepuller.Image{
ChainIDs: []string{"checksum"},
}, nil)
logger = lagertest.NewTestLogger("groot")
g = &groot.Groot{
Driver: driver,
Logger: logger,
ImagePuller: imagePuller,
}
})
Describe("Pull succeeding", func() {
var (
rootfsFileBuffer *bytes.Buffer
)
BeforeEach(func() {
rootfsFileBuffer = bytes.NewBuffer([]byte{})
driver.UnpackStub = func(logger lager.Logger, id string, parentIDs []string, layerTar io.Reader) (int64, error) {
bytesWritten, err := io.Copy(rootfsFileBuffer, layerTar)
Expect(err).NotTo(HaveOccurred())
return bytesWritten, nil
}
})
JustBeforeEach(func() {
Expect(g.Pull()).To(Succeed())
})
It("calls the image puller with the expected args", func() {
Expect(imagePuller.PullCallCount()).To(Equal(1))
_, spec := imagePuller.PullArgsForCall(0)
Expect(spec).To(Equal(imagepuller.ImageSpec{}))
})
})
Describe("Pull failing", func() {
var (
pullErr error
)
JustBeforeEach(func() {
pullErr = g.Pull()
})
Context("when image puller returns an error", func() {
BeforeEach(func() {
imagePuller.PullReturns(imagepuller.Image{}, errors.New("pull-failed"))
})
It("returns the error", func() {
Expect(pullErr).To(MatchError(ContainSubstring("pull-failed")))
})
})
})
})