add tests for kustomize config name handling

Signed-off-by: crabique <crabique@users.noreply.github.com>
This commit is contained in:
crabique 2025-03-10 17:24:20 +02:00
parent 3ae89361df
commit 9a8e210df8
6 changed files with 50 additions and 9 deletions

View File

@ -33,11 +33,12 @@ func TestScreeningLocalReader(t *testing.T) {
} }
nodes, err := r.Read() nodes, err := r.Read()
g.Expect(err).ToNot(HaveOccurred()) g.Expect(err).ToNot(HaveOccurred())
// the test fixture has three files that contain the marker: // the test fixture has four files that contain the marker:
// - otherns.yaml
// - marked.yaml // - marked.yaml
// - kustomization.yaml // - otherns.yaml
g.Expect(len(nodes)).To(Equal(3)) // - kustomization.yml
// - Kustomization
g.Expect(len(nodes)).To(Equal(4))
filesSeen := map[string]struct{}{} filesSeen := map[string]struct{}{}
for i := range nodes { for i := range nodes {
path, _, err := kioutil.GetFileAnnotations(nodes[i]) path, _, err := kioutil.GetFileAnnotations(nodes[i])
@ -46,8 +47,9 @@ func TestScreeningLocalReader(t *testing.T) {
} }
g.Expect(filesSeen).To(Equal(map[string]struct{}{ g.Expect(filesSeen).To(Equal(map[string]struct{}{
"marked.yaml": {}, "marked.yaml": {},
"kustomization.yaml": {},
"otherns.yaml": {}, "otherns.yaml": {},
"kustomization.yml": {},
"Kustomization": {},
})) }))
} }

View File

@ -0,0 +1,9 @@
# This is not intended to be a working kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- irrelevant.yaml
images:
- name: container
newName: index.repo.fake/updated # {"$imagepolicy": "automation-ns:policy:name"}
newTag: v1.0.1 # {"$imagepolicy": "automation-ns:policy:tag"}

View File

@ -0,0 +1,9 @@
# This is not intended to be a working kustomization
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- irrelevant.yaml
images:
- name: container
newName: replaced # {"$imagepolicy": "automation-ns:policy:name"}
newTag: v1 # {"$imagepolicy": "automation-ns:policy:tag"}

View File

@ -83,7 +83,14 @@ func TestUpdateWithSetters(t *testing.T) {
expectedResult := Result{ expectedResult := Result{
Files: map[string]FileResult{ Files: map[string]FileResult{
"kustomization.yaml": { "kustomization.yml": {
Objects: map[ObjectIdentifier][]ImageRef{
kustomizeResourceID: {
expectedImageRef,
},
},
},
"Kustomization": {
Objects: map[ObjectIdentifier][]ImageRef{ Objects: map[ObjectIdentifier][]ImageRef{
kustomizeResourceID: { kustomizeResourceID: {
expectedImageRef, expectedImageRef,
@ -111,7 +118,21 @@ func TestUpdateWithSetters(t *testing.T) {
expectedResultV2 := ResultV2{ expectedResultV2 := ResultV2{
ImageResult: expectedResult, ImageResult: expectedResult,
FileChanges: map[string]ObjectChanges{ FileChanges: map[string]ObjectChanges{
"kustomization.yaml": { "kustomization.yml": {
kustomizeResourceID: []Change{
{
OldValue: "replaced",
NewValue: "index.repo.fake/updated",
Setter: "automation-ns:policy:name",
},
{
OldValue: "v1",
NewValue: "v1.0.1",
Setter: "automation-ns:policy:tag",
},
},
},
"Kustomization": {
kustomizeResourceID: []Change{ kustomizeResourceID: []Change{
{ {
OldValue: "replaced", OldValue: "replaced",