@@ -14,6 +14,7 @@ limitations under the License.
14
14
package runfileconfig
15
15
16
16
import (
17
+ "fmt"
17
18
"os"
18
19
"path/filepath"
19
20
"strings"
32
33
runFileForPrecedenceRuleDaprDir = filepath .Join ("." , "testdata" , "test_run_config_precedence_rule_dapr_dir.yaml" )
33
34
runFileForLogDestination = filepath .Join ("." , "testdata" , "test_run_config_log_destination.yaml" )
34
35
runFileForMultiResourcePaths = filepath .Join ("." , "testdata" , "test_run_config_multiple_resources_paths.yaml" )
36
+
37
+ runFileForContainerImagePullPolicy = filepath .Join ("." , "testdata" , "test_run_config_container_image_pull_policy.yaml" )
38
+ runFileForContainerImagePullPolicyInvalid = filepath .Join ("." , "testdata" , "test_run_config_container_image_pull_policy_invalid.yaml" )
35
39
)
36
40
37
41
func TestRunConfigFile (t * testing.T ) {
@@ -251,6 +255,51 @@ func TestRunConfigFile(t *testing.T) {
251
255
})
252
256
}
253
257
258
+ func TestContainerImagePullPolicy (t * testing.T ) {
259
+ testcases := []struct {
260
+ name string
261
+ runfFile string
262
+ expectedPullPolicies []string
263
+ expectedBadPolicyValue string
264
+ expectedErr bool
265
+ }{
266
+ {
267
+ name : "default value is Always" ,
268
+ runfFile : validRunFilePath ,
269
+ expectedPullPolicies : []string {"Always" , "Always" },
270
+ expectedErr : false ,
271
+ },
272
+ {
273
+ name : "custom value is respected" ,
274
+ runfFile : runFileForContainerImagePullPolicy ,
275
+ expectedPullPolicies : []string {"IfNotPresent" , "Always" },
276
+ expectedErr : false ,
277
+ },
278
+ {
279
+ name : "invalid value is rejected" ,
280
+ runfFile : runFileForContainerImagePullPolicyInvalid ,
281
+ expectedPullPolicies : []string {"Always" , "Always" },
282
+ expectedBadPolicyValue : "Invalid" ,
283
+ expectedErr : true ,
284
+ },
285
+ }
286
+
287
+ for _ , tc := range testcases {
288
+ t .Run (tc .name , func (t * testing.T ) {
289
+ config := RunFileConfig {}
290
+ config .parseAppsConfig (tc .runfFile )
291
+ err := config .validateRunConfig (tc .runfFile )
292
+ if tc .expectedErr {
293
+ assert .Error (t , err )
294
+ assert .Contains (t , err .Error (), fmt .Sprintf ("invalid containerImagePullPolicy: %s, allowed values: Always, Never, IfNotPresent" , tc .expectedBadPolicyValue ))
295
+ return
296
+ }
297
+ assert .Equal (t , tc .expectedPullPolicies [0 ], config .Apps [0 ].ContainerImagePullPolicy )
298
+ assert .Equal (t , tc .expectedPullPolicies [1 ], config .Apps [1 ].ContainerImagePullPolicy )
299
+ })
300
+ }
301
+ }
302
+
254
303
func TestMultiResourcePathsResolution (t * testing.T ) {
255
304
config := RunFileConfig {}
256
305
0 commit comments