Merge pull request #1529 from Umair0343/patch-2

Update patch_test.go (Add Test Case for Non-Existent Image in GetPatchCmd)
This commit is contained in:
Matthias Bertschy
2023-11-26 11:54:28 +01:00
committed by GitHub
+16
View File
@@ -34,3 +34,19 @@ func TestGetPatchCmd(t *testing.T) {
err = cmd.RunE(&cobra.Command{}, []string{"patch", "--image", "docker.io/library/nginx:1.22"})
assert.Equal(t, expectedErrorMessage, err.Error())
}
func TestGetPatchCmdWithNonExistentImage(t *testing.T) {
// Create a mock Kubescape interface
mockKubescape := &mocks.MockIKubescape{}
// Call the GetPatchCmd function
cmd := GetPatchCmd(mockKubescape)
// Run the command with a non-existent image argument
err := cmd.RunE(&cobra.Command{}, []string{"patch", "--image", "non-existent-image"})
// Check that there is an error and the error message is as expected
expectedErrorMessage := "image tag is required"
assert.Error(t, err)
assert.Equal(t, expectedErrorMessage, err.Error())
}