mirror of https://github.com/docker/cli.git
Improve testing of never pull and always pull scenarios
Signed-off-by: Zander Mackie <zmackie@gmail.com>
This commit is contained in:
parent
ec56136d61
commit
ffba7659cc
|
@ -128,6 +128,7 @@ func TestCreateContainerPullsImageIfMissing(t *testing.T) {
|
||||||
func TestCreateContainerNeverPullsImage(t *testing.T) {
|
func TestCreateContainerNeverPullsImage(t *testing.T) {
|
||||||
imageName := "does-not-exist-locally"
|
imageName := "does-not-exist-locally"
|
||||||
responseCounter := 0
|
responseCounter := 0
|
||||||
|
pullCounter := 0
|
||||||
|
|
||||||
client := &fakeClient{
|
client := &fakeClient{
|
||||||
createContainerFunc: func(
|
createContainerFunc: func(
|
||||||
|
@ -145,7 +146,13 @@ func TestCreateContainerNeverPullsImage(t *testing.T) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
||||||
|
defer func() { pullCounter++ }()
|
||||||
|
switch pullCounter {
|
||||||
|
case 0:
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return ioutil.NopCloser(strings.NewReader("")), nil
|
||||||
|
default:
|
||||||
|
return nil, errors.New("unexpected pull")
|
||||||
|
}
|
||||||
},
|
},
|
||||||
infoFunc: func() (types.Info, error) {
|
infoFunc: func() (types.Info, error) {
|
||||||
return types.Info{IndexServerAddress: "http://indexserver"}, nil
|
return types.Info{IndexServerAddress: "http://indexserver"}, nil
|
||||||
|
@ -169,7 +176,9 @@ func TestCreateContainerNeverPullsImage(t *testing.T) {
|
||||||
|
|
||||||
func TestCreateContainerAlwaysPullsImage(t *testing.T) {
|
func TestCreateContainerAlwaysPullsImage(t *testing.T) {
|
||||||
imageName := "does-not-exist-locally"
|
imageName := "does-not-exist-locally"
|
||||||
|
pullTries := 7
|
||||||
responseCounter := 0
|
responseCounter := 0
|
||||||
|
pullCounter := 0
|
||||||
containerID := "abcdef"
|
containerID := "abcdef"
|
||||||
|
|
||||||
client := &fakeClient{
|
client := &fakeClient{
|
||||||
|
@ -181,13 +190,12 @@ func TestCreateContainerAlwaysPullsImage(t *testing.T) {
|
||||||
) (container.ContainerCreateCreatedBody, error) {
|
) (container.ContainerCreateCreatedBody, error) {
|
||||||
defer func() { responseCounter++ }()
|
defer func() { responseCounter++ }()
|
||||||
switch responseCounter {
|
switch responseCounter {
|
||||||
case 0:
|
|
||||||
return container.ContainerCreateCreatedBody{ID: containerID}, nil
|
|
||||||
default:
|
default:
|
||||||
return container.ContainerCreateCreatedBody{}, errors.New("unexpected")
|
return container.ContainerCreateCreatedBody{ID: containerID}, nil
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
imageCreateFunc: func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error) {
|
||||||
|
defer func() { pullCounter++ }()
|
||||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
return ioutil.NopCloser(strings.NewReader("")), nil
|
||||||
},
|
},
|
||||||
infoFunc: func() (types.Info, error) {
|
infoFunc: func() (types.Info, error) {
|
||||||
|
@ -201,6 +209,7 @@ func TestCreateContainerAlwaysPullsImage(t *testing.T) {
|
||||||
},
|
},
|
||||||
HostConfig: &container.HostConfig{},
|
HostConfig: &container.HostConfig{},
|
||||||
}
|
}
|
||||||
|
for i := 0; i < pullTries; i++ {
|
||||||
body, err := createContainer(context.Background(), cli, config, &createOptions{
|
body, err := createContainer(context.Background(), cli, config, &createOptions{
|
||||||
name: "name",
|
name: "name",
|
||||||
platform: runtime.GOOS,
|
platform: runtime.GOOS,
|
||||||
|
@ -210,6 +219,9 @@ func TestCreateContainerAlwaysPullsImage(t *testing.T) {
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
expected := container.ContainerCreateCreatedBody{ID: containerID}
|
expected := container.ContainerCreateCreatedBody{ID: containerID}
|
||||||
assert.Check(t, is.DeepEqual(expected, *body))
|
assert.Check(t, is.DeepEqual(expected, *body))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Check(t, is.Equal(responseCounter, pullCounter))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
|
func TestNewCreateCommandWithContentTrustErrors(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue