@@ -9,9 +9,11 @@ import (
99 "github.com/argoproj-labs/argocd-image-updater/pkg/image"
1010 "github.com/argoproj-labs/argocd-image-updater/pkg/tag"
1111
12+ "sigs.k8s.io/kustomize/api/types"
13+ kyaml "sigs.k8s.io/kustomize/kyaml/yaml"
14+
1215 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1"
1316 "github.com/stretchr/testify/assert"
14- image2 "sigs.k8s.io/kustomize/pkg/image"
1517)
1618
1719func Test_TemplateCommitMessage (t * testing.T ) {
@@ -44,36 +46,36 @@ func Test_parseImageOverride(t *testing.T) {
4446 cases := []struct {
4547 name string
4648 override v1alpha1.KustomizeImage
47- expected image2 .Image
49+ expected types .Image
4850 }{
49- {"tag update" , "ghcr.io:1234/foo/foo:123" , image2 .Image {
51+ {"tag update" , "ghcr.io:1234/foo/foo:123" , types .Image {
5052 Name : "ghcr.io:1234/foo/foo" ,
5153 NewTag : "123" ,
5254 }},
53- {"image update" , "ghcr.io:1234/foo/foo=ghcr.io:1234/bar" , image2 .Image {
55+ {"image update" , "ghcr.io:1234/foo/foo=ghcr.io:1234/bar" , types .Image {
5456 Name : "ghcr.io:1234/foo/foo" ,
5557 NewName : "ghcr.io:1234/bar" ,
5658 }},
57- {"update everything" , "ghcr.io:1234/foo/foo=1234.foo.com:9876/bar:123" , image2 .Image {
59+ {"update everything" , "ghcr.io:1234/foo/foo=1234.foo.com:9876/bar:123" , types .Image {
5860 Name : "ghcr.io:1234/foo/foo" ,
5961 NewName : "1234.foo.com:9876/bar" ,
6062 NewTag : "123" ,
6163 }},
62- {"change registry and tag" , "ghcr.io:1234/foo/foo=1234.dkr.ecr.us-east-1.amazonaws.com/bar:123" , image2 .Image {
64+ {"change registry and tag" , "ghcr.io:1234/foo/foo=1234.dkr.ecr.us-east-1.amazonaws.com/bar:123" , types .Image {
6365 Name : "ghcr.io:1234/foo/foo" ,
6466 NewName : "1234.dkr.ecr.us-east-1.amazonaws.com/bar" ,
6567 NewTag : "123" ,
6668 }},
67- {"change only registry" , "0001.dkr.ecr.us-east-1.amazonaws.com/bar=1234.dkr.ecr.us-east-1.amazonaws.com/bar" , image2 .Image {
69+ {"change only registry" , "0001.dkr.ecr.us-east-1.amazonaws.com/bar=1234.dkr.ecr.us-east-1.amazonaws.com/bar" , types .Image {
6870 Name : "0001.dkr.ecr.us-east-1.amazonaws.com/bar" ,
6971 NewName : "1234.dkr.ecr.us-east-1.amazonaws.com/bar" ,
7072 }},
71- {"change image and set digest" , "foo=acme/app@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , image2 .Image {
73+ {"change image and set digest" , "foo=acme/app@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , types .Image {
7274 Name : "foo" ,
7375 NewName : "acme/app" ,
7476 Digest : "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
7577 }},
76- {"set digest" , "acme/app@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , image2 .Image {
78+ {"set digest" , "acme/app@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" , types .Image {
7779 Name : "acme/app" ,
7880 Digest : "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" ,
7981 }},
@@ -86,3 +88,66 @@ func Test_parseImageOverride(t *testing.T) {
8688 }
8789
8890}
91+
92+ func Test_imagesFilter (t * testing.T ) {
93+ for _ , tt := range []struct {
94+ name string
95+ images v1alpha1.KustomizeImages
96+ expected string
97+ }{
98+ {name : "simple" , images : v1alpha1.KustomizeImages {"foo" }, expected : `
99+ images:
100+ - name: foo
101+ ` },
102+ {name : "tagged" , images : v1alpha1.KustomizeImages {"foo:bar" }, expected : `
103+ images:
104+ - name: foo
105+ newTag: bar
106+ ` },
107+ {name : "rename" , images : v1alpha1.KustomizeImages {"baz=foo:bar" }, expected : `
108+ images:
109+ - name: baz
110+ newName: foo
111+ newTag: bar
112+ ` },
113+ {name : "digest" , images : v1alpha1.KustomizeImages {"baz=foo@sha12345" }, expected : `
114+ images:
115+ - name: baz
116+ newName: foo
117+ digest: sha12345
118+ ` },
119+ {name : "digest simple" , images : v1alpha1.KustomizeImages {"foo@sha12345" }, expected : `
120+ images:
121+ - name: foo
122+ digest: sha12345
123+ ` },
124+ {name : "all" , images : v1alpha1.KustomizeImages {
125+ "foo" ,
126+ "foo=bar" , // merges with above
127+ "baz@sha12345" ,
128+ "bar:123" ,
129+ "foo=bar:123" , // merges and overwrites the first two
130+ }, expected : `
131+ images:
132+ - name: foo
133+ newName: bar
134+ newTag: "123"
135+ - name: baz
136+ digest: sha12345
137+ - name: bar
138+ newTag: "123"
139+ ` },
140+ } {
141+ t .Run (tt .name , func (t * testing.T ) {
142+ filter , err := imagesFilter (tt .images )
143+ assert .NoError (t , err )
144+
145+ node := kyaml .NewRNode (& kyaml.Node {Kind : kyaml .DocumentNode , Content : []* kyaml.Node {
146+ kyaml .NewMapRNode (nil ).YNode (),
147+ }})
148+ node , err = filter .Filter (node )
149+ assert .NoError (t , err )
150+ assert .YAMLEq (t , tt .expected , node .MustString ())
151+ })
152+ }
153+ }
0 commit comments