-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
and a small refactor
- Loading branch information
Showing
13 changed files
with
617 additions
and
24 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,83 @@ | ||
package merger | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
) | ||
|
||
func TestMerger(t *testing.T) { | ||
// Create a Merger resource. | ||
merger := &Merger{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "my-merger", | ||
}, | ||
Spec: mergerSpec{ | ||
Resources: []mergerResource{ | ||
{ | ||
Name: "my-resource", | ||
Input: resourceInput{ | ||
Method: Overlay, | ||
Files: resourceInputFiles{ | ||
Root: "../../examples/testdata", | ||
Sources: []string{ | ||
"input/dev.yaml", | ||
"input/stage.yaml", | ||
}, | ||
Destination: "input/base.yaml", | ||
}, | ||
}, | ||
Merge: resourceMerge{ | ||
Strategy: Append, | ||
}, | ||
Output: resourceOutput{ | ||
Format: Raw, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// | ||
// Schema. | ||
_, err := merger.Schema() | ||
if err != nil { | ||
t.Errorf("Failed to load schema: %v", err) | ||
} | ||
|
||
// | ||
// Default. | ||
err = merger.Default() | ||
if err != nil { | ||
t.Errorf("Failed to set defaults: %v", err) | ||
} | ||
// The trailing slash should be added to the root. | ||
assert.Equal(t, "../../examples/testdata/", merger.Spec.Resources[0].Input.Files.Root) | ||
// Create the output items as an empty map. | ||
assert.Equal(t, map[string]string{}, merger.Spec.Resources[0].Output.items) | ||
|
||
// | ||
// Validate. | ||
err = merger.Validate() | ||
if err != nil { | ||
t.Errorf("Failed to validate: %v", err) | ||
} | ||
|
||
// | ||
// Filter. | ||
rlItemsIn := []*yaml.RNode{} | ||
var rlItemsOut []*yaml.RNode | ||
|
||
rlItemsOut, err = merger.Filter(rlItemsIn) | ||
if err != nil { | ||
t.Errorf("Failed to filter resource list: %v", err) | ||
} | ||
// Output items should be two since the input method is "overlay". | ||
assert.Len(t, rlItemsOut, 2) | ||
|
||
// Verify that the filtered resource list contains the merged resource. | ||
// NOTE: Since the items are generated from a Map; hence the output order is no preserved. | ||
assert.Equal(t, "Pod", rlItemsOut[0].GetKind()) | ||
} |
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
Oops, something went wrong.