github.com/argoproj/argo-cd/v3@v3.2.1/util/hydrator/template_test.go (about) 1 package hydrator 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 9 "github.com/argoproj/argo-cd/v3/pkg/apis/application/v1alpha1" 10 "github.com/argoproj/argo-cd/v3/util/settings" 11 ) 12 13 func TestRender(t *testing.T) { 14 tests := []struct { 15 name string 16 metadata HydratorCommitMetadata 17 want string 18 wantErr bool 19 }{ 20 { 21 name: "author and multiple references", 22 metadata: HydratorCommitMetadata{ 23 RepoURL: "https://github.com/test/argocd-example-apps", 24 DrySHA: "3ff41cc5247197a6caf50216c4c76cc29d78a97d", 25 Author: "test <test@test.com>", 26 Date: metav1.Now().String(), 27 References: []v1alpha1.RevisionReference{ 28 { 29 Commit: &v1alpha1.CommitMetadata{ 30 Author: "ref test <ref-test@test.com>", 31 Subject: "test", 32 RepoURL: "https://github.com/test/argocd-example-apps", 33 SHA: "3ff41cc5247197a6caf50216c4c76cc29d78a97c", 34 }, 35 }, 36 { 37 Commit: &v1alpha1.CommitMetadata{ 38 Author: "ref test 2 <ref-test-2@test.com>", 39 Subject: "test 2", 40 RepoURL: "https://github.com/test/argocd-example-apps", 41 SHA: "abc12345678912345678912345678912345678912", 42 }, 43 }, 44 }, 45 Body: "testBody", 46 Subject: "testSubject", 47 }, 48 want: `3ff41cc: testSubject 49 50 testBody 51 52 Co-authored-by: ref test <ref-test@test.com> 53 Co-authored-by: ref test 2 <ref-test-2@test.com> 54 Co-authored-by: test <test@test.com> 55 `, 56 }, 57 { 58 name: "no references", 59 metadata: HydratorCommitMetadata{ 60 RepoURL: "https://github.com/test/argocd-example-apps", 61 DrySHA: "3ff41cc5247197a6caf50216c4c76cc29d78a97d", 62 Author: "test <test@test.com>", 63 Date: metav1.Now().String(), 64 Body: "testBody", 65 Subject: "testSubject", 66 }, 67 want: `3ff41cc: testSubject 68 69 testBody 70 71 Co-authored-by: test <test@test.com> 72 `, 73 }, 74 { 75 name: "no body", 76 metadata: HydratorCommitMetadata{ 77 RepoURL: "https://github.com/test/argocd-example-apps", 78 DrySHA: "3ff41cc5247197a6caf50216c4c76cc29d78a97d", 79 Author: "test <test@test.com>", 80 Date: metav1.Now().String(), 81 Subject: "testSubject", 82 }, 83 want: `3ff41cc: testSubject 84 85 Co-authored-by: test <test@test.com> 86 `, 87 }, 88 } 89 for _, tt := range tests { 90 t.Run(tt.name, func(t *testing.T) { 91 got, err := Render(settings.CommitMessageTemplate, tt.metadata) 92 if (err != nil) != tt.wantErr { 93 t.Errorf("Render() error = %v, wantErr %v", err, tt.wantErr) 94 return 95 } 96 assert.Equal(t, tt.want, got) 97 }) 98 } 99 }