-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ignore images flag on generate missing images list (#463)
* implement viper * add validator * remove viper and add tests * remove logs * fix flags * fix md * fix install docs * fix typo on dry run * rename confbytes to b * add docs to functions * add ignore images and check images flag * fix command name
- Loading branch information
Showing
5 changed files
with
136 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package rancher | ||
|
||
import "testing" | ||
|
||
const ( | ||
rancherRepoImage = "rancher/rancher" | ||
rancherVersion = "v2.9.0" | ||
) | ||
|
||
var ( | ||
imagesWithVersion = []string{ | ||
rancherRepoImage + ":" + rancherVersion, | ||
"rancher/rancher-agent:v2.9.0", | ||
"k3s-io/k3s:v1.25.4", | ||
} | ||
imagesWithoutVersion = []string{ | ||
rancherRepoImage, | ||
"rancher/rancher-agent", | ||
"k3s-io/k3s", | ||
} | ||
) | ||
|
||
func TestImageSliceToMap(t *testing.T) { | ||
images, err := imageSliceToMap(imagesWithoutVersion) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if _, ok := images[imagesWithoutVersion[0]]; !ok { | ||
t.Error("expected image not found on map " + imagesWithoutVersion[0]) | ||
} | ||
images, err = imageSliceToMap(imagesWithVersion) | ||
if err == nil { | ||
t.Error("expected to flag image with version as malformed") | ||
} | ||
} | ||
|
||
func TestValidateRepoImage(t *testing.T) { | ||
if err := validateRepoImage(rancherRepoImage); err != nil { | ||
t.Error(err) | ||
} | ||
if err := validateRepoImage(imagesWithVersion[0]); err == nil { | ||
t.Error("expected to flag image with version as malformed" + imagesWithVersion[0]) | ||
} | ||
} | ||
|
||
func TestSplitImageAndVersion(t *testing.T) { | ||
repoImage, version, err := splitImageAndVersion(imagesWithVersion[0]) | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if repoImage != rancherRepoImage { | ||
t.Error("expected repoImage to be " + rancherRepoImage + " instead, got " + repoImage) | ||
} | ||
if version != rancherVersion { | ||
t.Error("expected version to be " + rancherVersion + " instead, got " + version) | ||
} | ||
if _, _, err := splitImageAndVersion(imagesWithoutVersion[0]); err == nil { | ||
t.Error("expected to flag image without version as malformed " + imagesWithoutVersion[0]) | ||
} | ||
} |