mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
fix: return error instead of log.Fatalf() (#5625)
* fix: return error instead of log.Fatalf() * chore: add meaningful message to error output * chore: add meaningful message to fatal function
This commit is contained in:
@@ -64,7 +64,7 @@ func makeResAccumulator(t *testing.T) *ResAccumulator {
|
||||
"name": "backendTwo",
|
||||
}}).ResMap())
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
t.Fatalf("failed to append resources: %v", err)
|
||||
}
|
||||
return ra
|
||||
}
|
||||
@@ -143,22 +143,26 @@ func expectLog(t *testing.T, log bytes.Buffer, expect string) {
|
||||
func TestResolveVarsVarNeedsDisambiguation(t *testing.T) {
|
||||
ra := makeResAccumulator(t)
|
||||
rm0 := resmap.New()
|
||||
err := rm0.Append(
|
||||
provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "backendOne",
|
||||
"namespace": "fooNamespace",
|
||||
},
|
||||
}))
|
||||
|
||||
r, err := provider.NewDefaultDepProvider().GetResourceFactory().FromMap(
|
||||
map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Service",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": "backendOne",
|
||||
"namespace": "fooNamespace",
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
t.Fatalf("failed to get instance of resources: %v", err)
|
||||
}
|
||||
err = rm0.Append(r)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to append a resource to ResMap: %v", err)
|
||||
}
|
||||
err = ra.AppendAll(rm0)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected err: %v", err)
|
||||
t.Fatalf("failed to append a resource to ResAccumulator: %v", err)
|
||||
}
|
||||
|
||||
err = ra.MergeVars([]types.Var{
|
||||
@@ -227,7 +231,11 @@ func TestResolveVarConflicts(t *testing.T) {
|
||||
// create accumulators holding apparently conflicting vars that are not
|
||||
// actually in conflict because they point to the same concrete value.
|
||||
rm0 := resmap.New()
|
||||
err := rm0.Append(rf.FromMap(fooAws))
|
||||
r0, err0 := rf.FromMap(fooAws)
|
||||
if err0 != nil {
|
||||
t.Fatalf("failed to get instance of resources: %v", err0)
|
||||
}
|
||||
err := rm0.Append(r0)
|
||||
require.NoError(t, err)
|
||||
ac0 := MakeEmptyAccumulator()
|
||||
err = ac0.AppendAll(rm0)
|
||||
@@ -236,7 +244,11 @@ func TestResolveVarConflicts(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
rm1 := resmap.New()
|
||||
err = rm1.Append(rf.FromMap(barAws))
|
||||
r1, err1 := rf.FromMap(barAws)
|
||||
if err1 != nil {
|
||||
t.Fatalf("failed to get instance of resources: %v", err1)
|
||||
}
|
||||
err = rm1.Append(r1)
|
||||
require.NoError(t, err)
|
||||
ac1 := MakeEmptyAccumulator()
|
||||
err = ac1.AppendAll(rm1)
|
||||
@@ -255,7 +267,11 @@ func TestResolveVarConflicts(t *testing.T) {
|
||||
// two above (because it contains a variable whose name is used in the other
|
||||
// accumulators AND whose concrete values are different).
|
||||
rm2 := resmap.New()
|
||||
err = rm2.Append(rf.FromMap(barGcp))
|
||||
r2, err2 := rf.FromMap(barGcp)
|
||||
if err2 != nil {
|
||||
t.Fatalf("failed to get instance of resources: %v", err2)
|
||||
}
|
||||
err = rm2.Append(r2)
|
||||
require.NoError(t, err)
|
||||
ac2 := MakeEmptyAccumulator()
|
||||
err = ac2.AppendAll(rm2)
|
||||
|
||||
Reference in New Issue
Block a user