(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestCreateContainerImagePullPolicy(t *testing.T) { |
| 94 | const ( |
| 95 | imageName = "does-not-exist-locally" |
| 96 | containerID = "abcdef" |
| 97 | ) |
| 98 | config := &containerConfig{ |
| 99 | Config: &container.Config{ |
| 100 | Image: imageName, |
| 101 | }, |
| 102 | HostConfig: &container.HostConfig{}, |
| 103 | } |
| 104 | |
| 105 | cases := []struct { |
| 106 | PullPolicy string |
| 107 | ExpectedPulls int |
| 108 | ExpectedID string |
| 109 | ExpectedErrMsg string |
| 110 | ResponseCounter int |
| 111 | }{ |
| 112 | { |
| 113 | PullPolicy: PullImageMissing, |
| 114 | ExpectedPulls: 1, |
| 115 | ExpectedID: containerID, |
| 116 | }, { |
| 117 | PullPolicy: PullImageAlways, |
| 118 | ExpectedPulls: 1, |
| 119 | ExpectedID: containerID, |
| 120 | ResponseCounter: 1, // This lets us return a container on the first pull |
| 121 | }, { |
| 122 | PullPolicy: PullImageNever, |
| 123 | ExpectedPulls: 0, |
| 124 | ExpectedErrMsg: "error fake not found", |
| 125 | }, |
| 126 | } |
| 127 | for _, tc := range cases { |
| 128 | t.Run(tc.PullPolicy, func(t *testing.T) { |
| 129 | pullCounter := 0 |
| 130 | |
| 131 | apiClient := &fakeClient{ |
| 132 | createContainerFunc: func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error) { |
| 133 | defer func() { tc.ResponseCounter++ }() |
| 134 | switch tc.ResponseCounter { |
| 135 | case 0: |
| 136 | return client.ContainerCreateResult{}, fakeNotFound{} |
| 137 | default: |
| 138 | return client.ContainerCreateResult{ID: containerID}, nil |
| 139 | } |
| 140 | }, |
| 141 | imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) { |
| 142 | defer func() { pullCounter++ }() |
| 143 | return fakeStreamResult{ReadCloser: io.NopCloser(strings.NewReader(""))}, nil |
| 144 | }, |
| 145 | infoFunc: func() (client.SystemInfoResult, error) { |
| 146 | return client.SystemInfoResult{ |
| 147 | Info: system.Info{IndexServerAddress: "https://indexserver.example.com"}, |
| 148 | }, nil |
| 149 | }, |
| 150 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…