summaryrefslogtreecommitdiff
path: root/pkg/argocd/git_test.go
diff options
context:
space:
mode:
authorNick <83962080+nick-homex@users.noreply.github.com>2022-01-07 09:56:20 -0500
committerGitHub <noreply@github.com>2022-01-07 15:56:20 +0100
commita374b73039ef6e23564941bdfdbcafd2ea4fa227 (patch)
treeeed525e8aa93c75a8bf0f2b9161516394fb33b57 /pkg/argocd/git_test.go
parent8b401e40cbfe236d9ca678c205e3a01d2b7d2cd8 (diff)
feat: add ability to specify a different write and base branch (#304)
* add ability to specify a different write and base branch * format/spelling * add sha1 to template and truncate branch name length * add hasher error checking * document * spelling * correction to template docs * use sha256 and add warning to truncation * condense annotations into one * add some tests * add docs on omitting base branch
Diffstat (limited to 'pkg/argocd/git_test.go')
-rw-r--r--pkg/argocd/git_test.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/pkg/argocd/git_test.go b/pkg/argocd/git_test.go
index 92731d5..69f7027 100644
--- a/pkg/argocd/git_test.go
+++ b/pkg/argocd/git_test.go
@@ -42,6 +42,70 @@ updates image bar/baz tag '2.0' to '2.1'
})
}
+func Test_TemplateBranchName(t *testing.T) {
+ t.Run("Template branch name with image name", func(t *testing.T) {
+ exp := `image-updater-foo/bar-1.1-bar/baz-2.1`
+ tpl := "image-updater{{range .Images}}-{{.Name}}-{{.NewTag}}{{end}}"
+ cl := []ChangeEntry{
+ {
+ Image: image.NewFromIdentifier("foo/bar"),
+ OldTag: tag.NewImageTag("1.0", time.Now(), ""),
+ NewTag: tag.NewImageTag("1.1", time.Now(), ""),
+ },
+ {
+ Image: image.NewFromIdentifier("bar/baz"),
+ OldTag: tag.NewImageTag("2.0", time.Now(), ""),
+ NewTag: tag.NewImageTag("2.1", time.Now(), ""),
+ },
+ }
+ r := TemplateBranchName(tpl, cl)
+ assert.NotEmpty(t, r)
+ assert.Equal(t, exp, r)
+ })
+ t.Run("Template branch name with alias", func(t *testing.T) {
+ exp := `image-updater-bar-1.1`
+ tpl := "image-updater{{range .Images}}-{{.Alias}}-{{.NewTag}}{{end}}"
+ cl := []ChangeEntry{
+ {
+ Image: image.NewFromIdentifier("bar=0001.dkr.ecr.us-east-1.amazonaws.com/bar"),
+ OldTag: tag.NewImageTag("1.0", time.Now(), ""),
+ NewTag: tag.NewImageTag("1.1", time.Now(), ""),
+ },
+ }
+ r := TemplateBranchName(tpl, cl)
+ assert.NotEmpty(t, r)
+ assert.Equal(t, exp, r)
+ })
+ t.Run("Template branch name with hash", func(t *testing.T) {
+ // Expected value generated from https://emn178.github.io/online-tools/sha256.html
+ exp := `image-updater-0fcc2782543e4bb067c174c21bf44eb947f3e55c0d62c403e359c1c209cbd041`
+ tpl := "image-updater-{{.SHA256}}"
+ cl := []ChangeEntry{
+ {
+ Image: image.NewFromIdentifier("foo/bar"),
+ OldTag: tag.NewImageTag("1.0", time.Now(), ""),
+ NewTag: tag.NewImageTag("1.1", time.Now(), ""),
+ },
+ }
+ r := TemplateBranchName(tpl, cl)
+ assert.NotEmpty(t, r)
+ assert.Equal(t, exp, r)
+ })
+ t.Run("Template branch over 255 chars", func(t *testing.T) {
+ tpl := "image-updater-lorem-ipsum-dolor-sit-amet-consectetur-" +
+ "adipiscing-elit-phasellus-imperdiet-vitae-elit-quis-pulvinar-" +
+ "suspendisse-pulvinar-lacus-vel-semper-congue-enim-purus-posuere-" +
+ "orci-ut-vulputate-mi-ipsum-quis-ipsum-quisque-elit-arcu-lobortis-" +
+ "in-blandit-vel-pharetra-vel-urna-aliquam-euismod-elit-vel-mi"
+ exp := tpl[:255]
+ cl := []ChangeEntry{}
+ r := TemplateBranchName(tpl, cl)
+ assert.NotEmpty(t, r)
+ assert.Equal(t, exp, r)
+ assert.Len(t, r, 255)
+ })
+}
+
func Test_parseImageOverride(t *testing.T) {
cases := []struct {
name string