github.com/argoproj/argo-cd@v1.8.7/test/e2e/repo_management_test.go (about) 1 package e2e 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 9 repositorypkg "github.com/argoproj/argo-cd/pkg/apiclient/repository" 10 "github.com/argoproj/argo-cd/test/e2e/fixture" 11 "github.com/argoproj/argo-cd/test/e2e/fixture/app" 12 "github.com/argoproj/argo-cd/test/e2e/fixture/repos" 13 argoio "github.com/argoproj/argo-cd/util/io" 14 "github.com/argoproj/argo-cd/util/settings" 15 ) 16 17 func TestAddRemovePublicRepo(t *testing.T) { 18 app.Given(t).And(func() { 19 repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile) 20 _, err := fixture.RunCli("repo", "add", repoUrl) 21 assert.NoError(t, err) 22 23 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 24 assert.NoError(t, err) 25 defer argoio.Close(conn) 26 27 repo, err := repoClient.List(context.Background(), &repositorypkg.RepoQuery{}) 28 29 assert.Nil(t, err) 30 exists := false 31 for i := range repo.Items { 32 if repo.Items[i].Repo == repoUrl { 33 exists = true 34 break 35 } 36 } 37 assert.True(t, exists) 38 39 _, err = fixture.RunCli("repo", "rm", repoUrl) 40 assert.NoError(t, err) 41 42 repo, err = repoClient.List(context.Background(), &repositorypkg.RepoQuery{}) 43 assert.NoError(t, err) 44 exists = false 45 for i := range repo.Items { 46 if repo.Items[i].Repo == repoUrl { 47 exists = true 48 break 49 } 50 } 51 assert.False(t, exists) 52 }) 53 } 54 55 func TestUpsertExistingRepo(t *testing.T) { 56 app.Given(t).And(func() { 57 fixture.SetRepos(settings.RepositoryCredentials{URL: fixture.RepoURL(fixture.RepoURLTypeFile)}) 58 repoUrl := fixture.RepoURL(fixture.RepoURLTypeFile) 59 _, err := fixture.RunCli("repo", "add", repoUrl) 60 assert.NoError(t, err) 61 62 _, err = fixture.RunCli("repo", "add", repoUrl, "--username", fixture.GitUsername, "--password", fixture.GitPassword) 63 assert.Error(t, err) 64 65 _, err = fixture.RunCli("repo", "add", repoUrl, "--upsert", "--username", fixture.GitUsername, "--password", fixture.GitPassword) 66 assert.NoError(t, err) 67 }) 68 } 69 70 func TestAddRemoveHelmRepo(t *testing.T) { 71 app.Given(t).CustomCACertAdded().And(func() { 72 _, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm), 73 "--name", "testrepo", 74 "--type", "helm", 75 "--username", fixture.GitUsername, 76 "--password", fixture.GitPassword, 77 "--tls-client-cert-path", repos.CertPath, 78 "--tls-client-cert-key-path", repos.CertKeyPath) 79 assert.NoError(t, err) 80 81 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 82 assert.NoError(t, err) 83 defer argoio.Close(conn) 84 85 repo, err := repoClient.List(context.Background(), &repositorypkg.RepoQuery{}) 86 87 assert.NoError(t, err) 88 exists := false 89 for i := range repo.Items { 90 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 91 exists = true 92 break 93 } 94 } 95 assert.True(t, exists) 96 97 _, err = fixture.RunCli("repo", "rm", fixture.RepoURL(fixture.RepoURLTypeHelm)) 98 assert.NoError(t, err) 99 100 repo, err = repoClient.List(context.Background(), &repositorypkg.RepoQuery{}) 101 assert.NoError(t, err) 102 exists = false 103 for i := range repo.Items { 104 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 105 exists = true 106 break 107 } 108 } 109 assert.False(t, exists) 110 }) 111 112 } 113 114 func TestAddHelmRepoInsecureSkipVerify(t *testing.T) { 115 app.Given(t).And(func() { 116 _, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm), 117 "--name", "testrepo", 118 "--type", "helm", 119 "--username", fixture.GitUsername, 120 "--password", fixture.GitPassword, 121 "--insecure-skip-server-verification", 122 "--tls-client-cert-path", repos.CertPath, 123 "--tls-client-cert-key-path", repos.CertKeyPath) 124 125 if !assert.NoError(t, err) { 126 return 127 } 128 129 conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient() 130 if !assert.NoError(t, err) { 131 return 132 } 133 134 defer argoio.Close(conn) 135 136 repo, err := repoClient.List(context.Background(), &repositorypkg.RepoQuery{}) 137 138 if !assert.NoError(t, err) { 139 return 140 } 141 142 exists := false 143 for i := range repo.Items { 144 if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) { 145 exists = true 146 break 147 } 148 } 149 assert.True(t, exists) 150 }) 151 152 }