7
7
"strings"
8
8
"testing"
9
9
10
+ "github.com/docker/docker/api/types"
10
11
"github.com/docker/docker/api/types/image"
11
12
"github.com/go-logr/zapr"
12
13
"go.uber.org/zap"
@@ -19,6 +20,10 @@ func (c *fakeDockerClient) ImagePull(context.Context, string, image.PullOptions)
19
20
return io .NopCloser (strings .NewReader (c .imagePullContent )), nil
20
21
}
21
22
23
+ func (c * fakeDockerClient ) ImageInspectWithRaw (context.Context , string ) (types.ImageInspect , []byte , error ) {
24
+ return types.ImageInspect {}, nil , c .imageInspectErr
25
+ }
26
+
22
27
func TestContainerManagerPullImage (t * testing.T ) {
23
28
cases := []struct {
24
29
name string
@@ -27,6 +32,7 @@ func TestContainerManagerPullImage(t *testing.T) {
27
32
registry RegistryConnDetails
28
33
clientErr error
29
34
wantErr error
35
+ imageInspectErr error
30
36
}{
31
37
{
32
38
name : "Happy Path" ,
@@ -39,19 +45,27 @@ func TestContainerManagerPullImage(t *testing.T) {
39
45
responseContent : "{" ,
40
46
clientErr : errors .New ("You missed the shot" ),
41
47
wantErr : errors .New ("DOCKER PULL: You missed the shot" ),
48
+ imageInspectErr : errors .New ("Image not in local cache" ),
42
49
},
43
50
{
44
51
name : "pull error" ,
45
52
image : "yav.in/4/deathstar:nomedalforchewie" ,
46
53
responseContent : `{"error": "You missed the shot"}` ,
47
54
wantErr : errors .New ("DOCKER PULL: You missed the shot" ),
55
+ imageInspectErr : errors .New ("Image not in local cache" ),
56
+ },
57
+ {
58
+ name : "image already exists, no error" ,
59
+ image : "yav.in/4/deathstar:nomedalforchewie" ,
60
+ clientErr : errors .New ("You missed the shot" ),
61
+ wantErr : nil ,
48
62
},
49
63
}
50
64
51
65
for _ , tc := range cases {
52
66
t .Run (tc .name , func (t * testing.T ) {
53
67
logger := zapr .NewLogger (zap .Must (zap .NewDevelopment ()))
54
- mgr := NewContainerManager (logger , newFakeDockerClient ("" , tc .responseContent , 0 , 0 , tc .clientErr , nil ), tc .registry )
68
+ mgr := NewContainerManager (logger , newFakeDockerClient ("" , tc .responseContent , 0 , 0 , tc .clientErr , nil , withImageInspectErr ( tc . imageInspectErr ) ), tc .registry )
55
69
56
70
ctx := context .Background ()
57
71
gotErr := mgr .PullImage (ctx , tc .image )
0 commit comments