@@ -4260,27 +4260,67 @@ func TestSpecValidationIgnore(t *testing.T) {
42604260}
42614261
42624262func TestSpecValidationForArgs (t * testing.T ) {
4263- conf := testutil .TestConfig (t )
4264- oldSpecs := make (map [string ]* specs.Spec )
4265- spec , _ := sleepSpecConf (t )
4266- spec .Process .Cwd = "/bin"
4267- spec .Process .Args [0 ] = "/bin/sleep"
4268- oldSpecs ["container1" ] = spec
4263+ tests := []struct {
4264+ name string
4265+ args []string
4266+ restoreArgs []string
4267+ wantErr bool
4268+ }{
4269+ {
4270+ name : "base path same" ,
4271+ args : []string {"/bin/sleep" , "1000" },
4272+ restoreArgs : []string {"sleep" , "1000" },
4273+ wantErr : false ,
4274+ },
4275+ {
4276+ name : "executable path" ,
4277+ args : []string {"/bin/sleep" , "1000" },
4278+ restoreArgs : []string {"./sleep" , "1000" },
4279+ wantErr : false ,
4280+ },
4281+ {
4282+ name : "different args" ,
4283+ args : []string {"/bin/sleep" , "1000" , "1" },
4284+ restoreArgs : []string {"./sleep" , "1000" , "infinity" },
4285+ wantErr : true ,
4286+ },
4287+ {
4288+ name : "no base path" ,
4289+ args : []string {"/bin/sleep/" , "1000" , "1" },
4290+ restoreArgs : []string {"sleep" , "1000" , "infinity" },
4291+ wantErr : true ,
4292+ },
4293+ {
4294+ name : "same length with different path" ,
4295+ args : []string {"/bin/sleep" , "1000" , "1" },
4296+ restoreArgs : []string {"/bin/sheep" , "1000" , "1" },
4297+ wantErr : true ,
4298+ },
4299+ }
4300+ for _ , test := range tests {
4301+ t .Run (test .name , func (t * testing.T ) {
4302+ conf := testutil .TestConfig (t )
42694303
4270- newSpecs := make (map [string ]* specs.Spec )
4271- restoreSpec , _ := sleepSpecConf (t )
4272- restoreSpec .Process .Cwd = "/bin"
4273- restoreSpec .Process .Args [ 0 ] = "./sleep"
4274- newSpecs ["container1" ] = restoreSpec
4304+ oldSpecs := make (map [string ]* specs.Spec )
4305+ spec , _ := sleepSpecConf (t )
4306+ spec .Process .Cwd = "/bin"
4307+ spec .Process .Args = test . args
4308+ oldSpecs ["container1" ] = spec
42754309
4276- if err := specutils .RestoreValidateSpec (oldSpecs , newSpecs , conf ); err != nil {
4277- t .Errorf ("spec validation failed, got: %v, want: nil" , err )
4278- }
4310+ newSpecs := make (map [string ]* specs.Spec )
4311+ restoreSpec , _ := sleepSpecConf (t )
4312+ restoreSpec .Process .Cwd = "/bin"
4313+ restoreSpec .Process .Args = test .restoreArgs
4314+ newSpecs ["container1" ] = restoreSpec
42794315
4280- spec .Process .Args = append (spec .Process .Args , "1" )
4281- restoreSpec .Process .Args = append (restoreSpec .Process .Args , "infinity" )
4282- if err := specutils .RestoreValidateSpec (oldSpecs , newSpecs , conf ); err == nil {
4283- t .Errorf ("spec validation passed when we expected it to fail" )
4316+ err := specutils .RestoreValidateSpec (oldSpecs , newSpecs , conf )
4317+ if ! test .wantErr && err != nil {
4318+ t .Errorf ("spec validation failed, got: %v, want: nil" , err )
4319+ }
4320+ if test .wantErr && err == nil {
4321+ t .Errorf ("spec validation passed when we expected it to fail" )
4322+ }
4323+ })
42844324 }
42854325}
42864326
0 commit comments