mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Merge pull request #46074 from zjj2wry/set-image
Automatic merge from submit-queue (batch tested with PRs 45488, 45335, 45909, 46074, 46615) add test for set image validation **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: ```release-note ```
This commit is contained in:
commit
4979ae4b86
@ -70,3 +70,66 @@ func TestImageLocal(t *testing.T) {
|
|||||||
t.Errorf("did not set image: %s", buf.String())
|
t.Errorf("did not set image: %s", buf.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetImageValidation(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
name string
|
||||||
|
imageOptions *ImageOptions
|
||||||
|
expectErr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "test resource < 1 and filenames empty",
|
||||||
|
imageOptions: &ImageOptions{},
|
||||||
|
expectErr: "[one or more resources must be specified as <resource> <name> or <resource>/<name>, at least one image update is required]",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "test containerImages < 1",
|
||||||
|
imageOptions: &ImageOptions{
|
||||||
|
Resources: []string{"a", "b", "c"},
|
||||||
|
|
||||||
|
FilenameOptions: resource.FilenameOptions{
|
||||||
|
Filenames: []string{"testFile"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: "at least one image update is required",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "test containerImages > 1 and all containers are already specified by *",
|
||||||
|
imageOptions: &ImageOptions{
|
||||||
|
Resources: []string{"a", "b", "c"},
|
||||||
|
FilenameOptions: resource.FilenameOptions{
|
||||||
|
Filenames: []string{"testFile"},
|
||||||
|
},
|
||||||
|
ContainerImages: map[string]string{
|
||||||
|
"test": "test",
|
||||||
|
"*": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: "all containers are already specified by *, but saw more than one container_name=container_image pairs",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "sucess case",
|
||||||
|
imageOptions: &ImageOptions{
|
||||||
|
Resources: []string{"a", "b", "c"},
|
||||||
|
FilenameOptions: resource.FilenameOptions{
|
||||||
|
Filenames: []string{"testFile"},
|
||||||
|
},
|
||||||
|
ContainerImages: map[string]string{
|
||||||
|
"test": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectErr: "",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, testCase := range testCases {
|
||||||
|
err := testCase.imageOptions.Validate()
|
||||||
|
if err != nil {
|
||||||
|
if err.Error() != testCase.expectErr {
|
||||||
|
t.Errorf("[%s]:expect err:%s got err:%s", testCase.name, testCase.expectErr, err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil && (testCase.expectErr != "") {
|
||||||
|
t.Errorf("[%s]:expect err:%s got err:%v", testCase.name, testCase.expectErr, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user