mirror of
https://github.com/hanzoai/deploy.git
synced 2026-10-07 08:44:50 +00:00
go.mod still declared `module github.com/hanzoai/deploy` after the repo was renamed. A Go module path is not cosmetic — it is the resolvable location. So `go get github.com/hanzoai/cd` could not work, and anything importing this module had to spell a name that no longer exists at that address. The build log of v3.6.0 is where it surfaced: the compiler was still emitting github.com/hanzoai/deploy/cmd/cd/commands. 3541 import paths across 690 .go, 19 .proto, 4 .yaml, 3 .sh, 2 .mod, Procfile and Makefile. Plus the 62 ghcr.io/hanzoai/deploy image references, moved to ghcr.io/hanzoai/cd to match hanzo.yml's build target — a distinct string from the module path, replaced separately so neither could clobber the other. go mod tidy clean, CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./... clean. Co-authored-by: Hanzo Dev <[email protected]>
206 lines
6.5 KiB
Go
206 lines
6.5 KiB
Go
package e2e
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
repositorypkg "github.com/hanzoai/cd/pkg/apiclient/repository"
|
|
"github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
|
|
"github.com/hanzoai/cd/test/e2e/fixture"
|
|
"github.com/hanzoai/cd/test/e2e/fixture/app"
|
|
"github.com/hanzoai/cd/test/e2e/fixture/repos"
|
|
"github.com/hanzoai/cd/util/errors"
|
|
utilio "github.com/hanzoai/cd/util/io"
|
|
)
|
|
|
|
func TestAddRemovePublicRepo(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeFile)
|
|
_, err := fixture.RunCli("repo", "add", repoURL)
|
|
require.NoError(t, err)
|
|
|
|
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
|
require.NoError(t, err)
|
|
defer utilio.Close(conn)
|
|
|
|
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
|
|
|
require.NoError(t, err)
|
|
exists := false
|
|
for i := range repo.Items {
|
|
if repo.Items[i].Repo == repoURL {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, exists)
|
|
|
|
_, err = fixture.RunCli("repo", "rm", repoURL)
|
|
require.NoError(t, err)
|
|
|
|
repo, err = repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
|
require.NoError(t, err)
|
|
exists = false
|
|
for i := range repo.Items {
|
|
if repo.Items[i].Repo == repoURL {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
assert.False(t, exists)
|
|
})
|
|
}
|
|
|
|
func TestGetRepoWithInheritedCreds(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
// create repo credentials
|
|
errors.NewHandler(t).FailOnErr(fixture.RunCli("repocreds", "add", fixture.RepoURL(fixture.RepoURLTypeHTTPSOrg), "--github-app-id", fixture.GithubAppID, "--github-app-installation-id", fixture.GithubAppInstallationID, "--github-app-private-key-path", repos.CertKeyPath(t)))
|
|
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeHTTPS)
|
|
|
|
// Hack: First we need to create repo with valid credentials
|
|
errors.NewHandler(t).FailOnErr(fixture.RunCli("repo", "add", repoURL, "--username", fixture.GitUsername, "--password", fixture.GitPassword, "--insecure-skip-server-verification"))
|
|
|
|
// Then, we remove username/password so that the repo inherits the credentials from our repocreds
|
|
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
|
require.NoError(t, err)
|
|
defer utilio.Close(conn)
|
|
|
|
_, err = repoClient.UpdateRepository(t.Context(), &repositorypkg.RepoUpdateRequest{
|
|
Repo: &v1alpha1.Repository{
|
|
Repo: repoURL,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// CLI output should indicate that repo has inherited credentials
|
|
out, err := fixture.RunCli("repo", "get", repoURL)
|
|
require.NoError(t, err)
|
|
assert.Contains(t, out, "inherited")
|
|
|
|
_, err = fixture.RunCli("repo", "rm", repoURL)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestUpsertExistingRepo(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeFile)
|
|
_, err := fixture.RunCli("repo", "add", repoURL)
|
|
require.NoError(t, err)
|
|
|
|
_, err = fixture.RunCli("repo", "add", repoURL, "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
|
require.Error(t, err)
|
|
|
|
_, err = fixture.RunCli("repo", "add", repoURL, "--upsert", "--username", fixture.GitUsername, "--password", fixture.GitPassword)
|
|
require.NoError(t, err)
|
|
})
|
|
}
|
|
|
|
func TestAddRemoveHelmRepo(t *testing.T) {
|
|
app.Given(t).CustomCACertAdded().And(func() {
|
|
_, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm),
|
|
"--name", "testrepo",
|
|
"--type", "helm",
|
|
"--username", fixture.GitUsername,
|
|
"--password", fixture.GitPassword,
|
|
"--tls-client-cert-path", repos.CertPath(t),
|
|
"--tls-client-cert-key-path", repos.CertKeyPath(t))
|
|
require.NoError(t, err)
|
|
|
|
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
|
require.NoError(t, err)
|
|
defer utilio.Close(conn)
|
|
|
|
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
|
|
|
require.NoError(t, err)
|
|
exists := false
|
|
for i := range repo.Items {
|
|
if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, exists)
|
|
|
|
_, err = fixture.RunCli("repo", "rm", fixture.RepoURL(fixture.RepoURLTypeHelm))
|
|
require.NoError(t, err)
|
|
|
|
repo, err = repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
|
require.NoError(t, err)
|
|
exists = false
|
|
for i := range repo.Items {
|
|
if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
assert.False(t, exists)
|
|
})
|
|
}
|
|
|
|
func TestAddHelmRepoInsecureSkipVerify(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
_, err := fixture.RunCli("repo", "add", fixture.RepoURL(fixture.RepoURLTypeHelm),
|
|
"--name", "testrepo",
|
|
"--type", "helm",
|
|
"--username", fixture.GitUsername,
|
|
"--password", fixture.GitPassword,
|
|
"--insecure-skip-server-verification",
|
|
"--tls-client-cert-path", repos.CertPath(t),
|
|
"--tls-client-cert-key-path", repos.CertKeyPath(t))
|
|
|
|
require.NoError(t, err)
|
|
|
|
conn, repoClient, err := fixture.ArgoCDClientset.NewRepoClient()
|
|
require.NoError(t, err)
|
|
|
|
defer utilio.Close(conn)
|
|
|
|
repo, err := repoClient.ListRepositories(t.Context(), &repositorypkg.RepoQuery{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
exists := false
|
|
for i := range repo.Items {
|
|
if repo.Items[i].Repo == fixture.RepoURL(fixture.RepoURLTypeHelm) {
|
|
exists = true
|
|
break
|
|
}
|
|
}
|
|
assert.True(t, exists)
|
|
})
|
|
}
|
|
|
|
func TestFailOnPrivateRepoCreationWithPasswordAndBearerToken(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeFile)
|
|
_, err := fixture.RunCli("repo", "add", repoURL, "--password", fixture.GitPassword, "--bearer-token", fixture.GitBearerToken)
|
|
require.ErrorContains(t, err, "only --bearer-token or --password is allowed, not both")
|
|
})
|
|
}
|
|
|
|
func TestFailOnCreatePrivateNonHTTPSRepoWithBearerToken(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeFile)
|
|
_, err := fixture.RunCli("repo", "add", repoURL, "--bearer-token", fixture.GitBearerToken)
|
|
require.ErrorContains(t, err, "--bearer-token is only supported for HTTPS repositories")
|
|
})
|
|
}
|
|
|
|
func TestFailOnCreatePrivateNonGitRepoWithBearerToken(t *testing.T) {
|
|
app.Given(t).And(func() {
|
|
repoURL := fixture.RepoURL(fixture.RepoURLTypeHelm)
|
|
_, err := fixture.RunCli("repo", "add", repoURL, "--bearer-token", fixture.GitBearerToken,
|
|
"--insecure-skip-server-verification",
|
|
"--tls-client-cert-path", repos.CertPath(t),
|
|
"--tls-client-cert-key-path", repos.CertKeyPath(t),
|
|
"--name", "testrepo",
|
|
"--type", "helm")
|
|
require.ErrorContains(t, err, "--bearer-token is only supported for Git repositories")
|
|
})
|
|
}
|