-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --no-verify flag to edit add resource command #5333
Changes from 7 commits
f3b34c4
df0cd3c
039b05f
cb5b241
0d854a5
c3a4f3e
5936a89
7138423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import ( | |
"reflect" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"sigs.k8s.io/kustomize/api/ifc" | ||
"sigs.k8s.io/kustomize/kyaml/filesys" | ||
) | ||
|
@@ -21,26 +22,18 @@ func TestConvertToMap(t *testing.T) { | |
expected["g"] = "h:k" | ||
|
||
result, err := ConvertToMap(args, "annotation") | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err.Error()) | ||
} | ||
require.NoError(t, err, "unexpected error") | ||
|
||
eq := reflect.DeepEqual(expected, result) | ||
if !eq { | ||
t.Errorf("Converted map does not match expected, expected: %v, result: %v\n", expected, result) | ||
} | ||
require.True(t, eq, "Converted map does not match expected") | ||
} | ||
|
||
func TestConvertToMapError(t *testing.T) { | ||
args := "a:b,c:\"d\",:f:g" | ||
|
||
_, err := ConvertToMap(args, "annotation") | ||
if err == nil { | ||
t.Errorf("expected an error") | ||
} | ||
if err.Error() != "invalid annotation: ':f:g' (need k:v pair where v may be quoted)" { | ||
t.Errorf("incorrect error: %v", err.Error()) | ||
} | ||
require.Error(t, err, "expected error but did not receive one") | ||
require.Equal(t, "invalid annotation: ':f:g' (need k:v pair where v may be quoted)", err.Error(), "incorrect error") | ||
} | ||
|
||
func TestConvertSliceToMap(t *testing.T) { | ||
|
@@ -52,14 +45,10 @@ func TestConvertSliceToMap(t *testing.T) { | |
expected["g"] = "h:k" | ||
|
||
result, err := ConvertSliceToMap(args, "annotation") | ||
if err != nil { | ||
t.Errorf("unexpected error: %v", err.Error()) | ||
} | ||
require.NoError(t, err, "unexpected error") | ||
|
||
eq := reflect.DeepEqual(expected, result) | ||
if !eq { | ||
t.Errorf("Converted map does not match expected, expected: %v, result: %v\n", expected, result) | ||
} | ||
require.True(t, eq, "Converted map does not match expected") | ||
} | ||
|
||
func TestGlobPatternsWithLoaderRemoteFile(t *testing.T) { | ||
|
@@ -71,34 +60,30 @@ func TestGlobPatternsWithLoaderRemoteFile(t *testing.T) { | |
} | ||
|
||
// test load remote file | ||
resources, err := GlobPatternsWithLoader(fSys, ldr, []string{httpPath}) | ||
if err != nil { | ||
t.Fatalf("unexpected load error: %v", err) | ||
} | ||
if len(resources) != 1 || resources[0] != httpPath { | ||
t.Fatalf("incorrect resources: %v", resources) | ||
} | ||
resources, err := GlobPatternsWithLoader(fSys, ldr, []string{httpPath}, false) | ||
require.NoError(t, err, "unexpected load error") | ||
require.Equal(t, 1, len(resources), "incorrect resources") | ||
require.Equal(t, httpPath, resources[0], "incorrect resources") | ||
|
||
// test load local and remote file | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{httpPath, "/test.yml"}) | ||
if err != nil { | ||
t.Fatalf("unexpected load error: %v", err) | ||
} | ||
if len(resources) != 2 || resources[0] != httpPath || resources[1] != "/test.yml" { | ||
t.Fatalf("incorrect resources: %v", resources) | ||
} | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{httpPath, "/test.yml"}, false) | ||
require.NoError(t, err, "unexpected load error") | ||
require.Equal(t, 2, len(resources), "incorrect resources") | ||
require.Equal(t, httpPath, resources[0], "incorrect resources") | ||
require.Equal(t, "/test.yml", resources[1], "incorrect resources") | ||
|
||
// test load invalid file | ||
invalidURL := "http://invalid" | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{invalidURL}) | ||
if err == nil { | ||
t.Fatalf("expected error but did not receive one") | ||
} else if err.Error() != invalidURL+" has no match: "+invalidURL+" not exist" { | ||
t.Fatalf("unexpected load error: %v", err) | ||
} | ||
if len(resources) > 0 { | ||
t.Fatalf("incorrect resources: %v", resources) | ||
} | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{invalidURL}, false) | ||
require.Error(t, err, "expected error but did not receive one") | ||
require.Equal(t, invalidURL+" has no match: "+invalidURL+" not exist", err.Error(), "unexpected load error") | ||
require.Equal(t, 0, len(resources), "incorrect resources") | ||
|
||
// test load unreachable remote file with skipped verification | ||
resources, err = GlobPatternsWithLoader(fSys, ldr, []string{invalidURL}, true) | ||
require.NoError(t, err, "unexpected load error") | ||
require.Equal(t, 1, len(resources), "incorrect resources") | ||
require.Equal(t, invalidURL, resources[0], "incorrect resources") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for fixing up these tests and adding one for this feature. I think it might be nice to rewrite these tests using test structs and subtests, here is an example of this for the remove tests, so that it is easier to read and distinguish each test. You don't need to do this as part of this PR, but it would be a welcome change if you'd like to submit a follow-up PR to do so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was also thinking about that when I refactored the tests. Let me tackle that in a separate PR. |
||
} | ||
|
||
type fakeLoader struct { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For parity with the flag we are adding to kustomize localize (#5276), can we likewise name this flag
--no-verify
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be better. I've renamed the flag.