github.com/argoproj/argo-cd/v2@v2.10.5/test/e2e/app_multiple_sources_test.go (about) 1 package e2e 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 . "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" 9 . "github.com/argoproj/argo-cd/v2/test/e2e/fixture" 10 . "github.com/argoproj/argo-cd/v2/test/e2e/fixture/app" 11 . "github.com/argoproj/argo-cd/v2/util/argo" 12 ) 13 14 func TestMultiSourceAppCreation(t *testing.T) { 15 sources := []ApplicationSource{{ 16 RepoURL: RepoURL(RepoURLTypeFile), 17 Path: guestbookPath, 18 }, { 19 RepoURL: RepoURL(RepoURLTypeFile), 20 Path: "two-nice-pods", 21 }} 22 ctx := Given(t) 23 ctx. 24 Sources(sources). 25 When(). 26 CreateMultiSourceAppFromFile(). 27 Then(). 28 And(func(app *Application) { 29 assert.Equal(t, Name(), app.Name) 30 for i, source := range app.Spec.GetSources() { 31 assert.Equal(t, sources[i].RepoURL, source.RepoURL) 32 assert.Equal(t, sources[i].Path, source.Path) 33 } 34 assert.Equal(t, DeploymentNamespace(), app.Spec.Destination.Namespace) 35 assert.Equal(t, KubernetesInternalAPIServerAddr, app.Spec.Destination.Server) 36 }). 37 Expect(Event(EventReasonResourceCreated, "create")). 38 And(func(_ *Application) { 39 // app should be listed 40 output, err := RunCli("app", "list") 41 assert.NoError(t, err) 42 assert.Contains(t, output, Name()) 43 }). 44 Expect(Success("")). 45 Given().Timeout(60). 46 When().Wait().Then(). 47 Expect(Success("")). 48 And(func(app *Application) { 49 statusByName := map[string]SyncStatusCode{} 50 for _, r := range app.Status.Resources { 51 statusByName[r.Name] = r.Status 52 } 53 // check if the app has 3 resources, guestbook and 2 pods 54 assert.Len(t, statusByName, 3) 55 assert.Equal(t, SyncStatusCodeSynced, statusByName["pod-1"]) 56 assert.Equal(t, SyncStatusCodeSynced, statusByName["pod-2"]) 57 assert.Equal(t, SyncStatusCodeSynced, statusByName["guestbook-ui"]) 58 }) 59 } 60 61 func TestMultiSourceAppWithHelmExternalValueFiles(t *testing.T) { 62 sources := []ApplicationSource{{ 63 RepoURL: RepoURL(RepoURLTypeFile), 64 Ref: "values", 65 }, { 66 RepoURL: "https://github.com/argoproj/argocd-example-apps.git", 67 TargetRevision: "HEAD", 68 Path: "helm-guestbook", 69 Helm: &ApplicationSourceHelm{ 70 ReleaseName: "helm-guestbook", 71 ValueFiles: []string{ 72 "$values/multiple-source-values/values.yaml", 73 }, 74 }, 75 }} 76 ctx := Given(t) 77 ctx. 78 Sources(sources). 79 When(). 80 CreateMultiSourceAppFromFile(). 81 Then(). 82 And(func(app *Application) { 83 assert.Equal(t, Name(), app.Name) 84 for i, source := range app.Spec.GetSources() { 85 assert.Equal(t, sources[i].RepoURL, source.RepoURL) 86 assert.Equal(t, sources[i].Path, source.Path) 87 } 88 assert.Equal(t, DeploymentNamespace(), app.Spec.Destination.Namespace) 89 assert.Equal(t, KubernetesInternalAPIServerAddr, app.Spec.Destination.Server) 90 }). 91 Expect(Event(EventReasonResourceCreated, "create")). 92 And(func(_ *Application) { 93 // app should be listed 94 output, err := RunCli("app", "list") 95 assert.NoError(t, err) 96 assert.Contains(t, output, Name()) 97 }). 98 Expect(Success("")). 99 Given().Timeout(60). 100 When().Wait().Then(). 101 Expect(Success("")). 102 And(func(app *Application) { 103 statusByName := map[string]SyncStatusCode{} 104 for _, r := range app.Status.Resources { 105 statusByName[r.Name] = r.Status 106 } 107 // check if the app has 3 resources, guestbook and 2 pods 108 assert.Len(t, statusByName, 1) 109 assert.Equal(t, SyncStatusCodeSynced, statusByName["helm-guestbook"]) 110 }) 111 } 112 113 func TestMultiSourceAppWithSourceOverride(t *testing.T) { 114 sources := []ApplicationSource{{ 115 RepoURL: RepoURL(RepoURLTypeFile), 116 Path: guestbookPath, 117 }, { 118 RepoURL: RepoURL(RepoURLTypeFile), 119 Path: "two-nice-pods", 120 }, { 121 RepoURL: RepoURL(RepoURLTypeFile), 122 Path: "multiple-source-values", 123 }} 124 ctx := Given(t) 125 ctx. 126 Sources(sources). 127 When(). 128 CreateMultiSourceAppFromFile(). 129 Then(). 130 And(func(app *Application) { 131 assert.Equal(t, Name(), app.Name) 132 for i, source := range app.Spec.GetSources() { 133 assert.Equal(t, sources[i].RepoURL, source.RepoURL) 134 assert.Equal(t, sources[i].Path, source.Path) 135 } 136 assert.Equal(t, DeploymentNamespace(), app.Spec.Destination.Namespace) 137 assert.Equal(t, KubernetesInternalAPIServerAddr, app.Spec.Destination.Server) 138 }). 139 Expect(Event(EventReasonResourceCreated, "create")). 140 And(func(_ *Application) { 141 // app should be listed 142 output, err := RunCli("app", "list") 143 assert.NoError(t, err) 144 assert.Contains(t, output, Name()) 145 }). 146 Expect(Success("")). 147 Given().Timeout(60). 148 When().Wait().Then(). 149 Expect(Success("")). 150 And(func(app *Application) { 151 statusByName := map[string]SyncStatusCode{} 152 for _, r := range app.Status.Resources { 153 statusByName[r.Name] = r.Status 154 } 155 // check if the app has 3 resources, guestbook and 2 pods 156 assert.Len(t, statusByName, 3) 157 assert.Equal(t, SyncStatusCodeSynced, statusByName["pod-1"]) 158 assert.Equal(t, SyncStatusCodeSynced, statusByName["pod-2"]) 159 assert.Equal(t, SyncStatusCodeSynced, statusByName["guestbook-ui"]) 160 161 // check if label was added to the pod to make sure resource was taken from the later source 162 output, err := Run("", "kubectl", "describe", "pods", "pod-1", "-n", DeploymentNamespace()) 163 assert.NoError(t, err) 164 assert.Contains(t, output, "foo=bar") 165 }) 166 }