Files
cd/test/e2e/scoped_repository_test.go
zeekay 31c64ef661 test, applicationset: drop Argo branding, fix bugs it was hiding
Rename test names, comments, fixture data, and mock GitHub/webhook
responses that still said Argo/ArgoCD/argocd/argoproj in our own
voice, matching the hanzocd-* binary/configmap names and the
apps.hanzo.ai CRD/annotation domain already established elsewhere
in the fork. Also drop the dated argov1alpha1/argoprojiov1alpha1
import aliases for our own v1alpha1 API package.

Restore the CRD groups a prior blind rename had mangled on a
vendored third-party Argo Workflows example manifest back to the
real argoproj.io, and fix several places where an earlier
half-finished rename had gone silently wrong instead of just being
cosmetic: stale CD_BINARY_NAME values and a stale
--argocd-repo-server flag no longer recognized by the binary, cert
filenames and an ssh_known_hosts alias that didn't match what's
actually on disk, a namespace and a kustomize image substitution
that were silent no-ops, and a test assertion regex that could
never match its own fixture.

External lookup keys we don't control are left byte-exact:
quay.io/argoprojlabs images, the docker.io/argoproj CI builder
image, live argoproj/argo-workflows release URLs, the generated
ArgoprojV1alpha1() clientset method, and the Makefile-coupled
/tmp/argo-e2e and GOPATH mount conventions.
2026-09-05 01:07:59 -07:00

273 lines
6.3 KiB
Go

package e2e
import (
"testing"
"github.com/hanzoai/cd/test/e2e/fixture"
"github.com/hanzoai/cd/pkg/apiclient/project"
"github.com/stretchr/testify/assert"
. "github.com/hanzoai/cd/pkg/apis/application/v1alpha1"
accountFixture "github.com/hanzoai/cd/test/e2e/fixture/account"
projectFixture "github.com/hanzoai/cd/test/e2e/fixture/project"
repoFixture "github.com/hanzoai/cd/test/e2e/fixture/repos"
)
func TestCreateRepositoryWithProject(t *testing.T) {
ctx := projectFixture.Given(t).Name("cd-project")
prjConsequence := ctx.
When().
Create().
Then()
path := "https://github.com/hanzoai/cd.git"
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project(ctx.GetName()).
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, path, r.Repo)
assert.Equal(t, ctx.GetName(), r.Project)
prjConsequence.And(func(projectResponse *project.DetailedProjectsResponse, _ error) {
assert.Len(t, projectResponse.Repositories, 1)
assert.Equal(t, projectResponse.Repositories[0].Repo, path)
})
})
}
func TestCreateRepositoryNonAdminUserPermissionDenied(t *testing.T) {
ctx := accountFixture.Given(t)
ctx.Name("test").
When().
Create().
Login()
path := "https://github.com/hanzoai/cd.git"
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("cd-project").
IgnoreErrors().
Create().
Then().
AndCLIOutput(func(_ string, err error) {
assert.ErrorContains(t, err, "PermissionDenied desc = permission denied: repositories, create")
})
}
func TestCreateRepositoryNonAdminUserWithWrongProject(t *testing.T) {
ctx := accountFixture.Given(t)
ctx.Name("test").
When().
Create().
Login().
SetPermissions([]fixture.ACL{
{
Resource: "repositories",
Action: "*",
Scope: "wrong-project/*",
},
}, "org-admin")
path := "https://github.com/hanzoai/cd.git"
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("cd-project").
IgnoreErrors().
Create().
Then().
AndCLIOutput(func(_ string, err error) {
assert.ErrorContains(t, err, "PermissionDenied desc = permission denied: repositories, create")
})
}
func TestDeleteRepositoryRbacAllowed(t *testing.T) {
ctx := accountFixture.Given(t)
ctx.Name("test").
When().
Create().
Login().
SetPermissions([]fixture.ACL{
{
Resource: "repositories",
Action: "create",
Scope: "cd-project/*",
},
{
Resource: "repositories",
Action: "delete",
Scope: "cd-project/*",
},
{
Resource: "repositories",
Action: "get",
Scope: "cd-project/*",
},
}, "org-admin")
path := "https://github.com/hanzoai/cd.git"
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("cd-project").
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, r.Repo, path)
assert.Equal(t, "cd-project", r.Project)
}).
When().
Delete().
Then().
AndCLIOutput(func(output string, _ error) {
assert.Contains(t, output, "Repository 'https://github.com/hanzoai/cd.git' removed")
})
}
func TestDeleteRepositoryRbacDenied(t *testing.T) {
ctx := accountFixture.Given(t)
ctx.Name("test").
When().
Create().
Login().
SetPermissions([]fixture.ACL{
{
Resource: "repositories",
Action: "create",
Scope: "cd-project/*",
},
{
Resource: "repositories",
Action: "delete",
Scope: "cd-pr/*",
},
{
Resource: "repositories",
Action: "get",
Scope: "cd-project/*",
},
}, "org-admin")
path := "https://github.com/hanzoai/cd.git"
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("cd-project").
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, r.Repo, path)
assert.Equal(t, "cd-project", r.Project)
}).
When().
IgnoreErrors().
Delete().
Then().
AndCLIOutput(func(_ string, err error) {
assert.ErrorContains(t, err, "PermissionDenied desc = permission denied: repositories, delete")
})
}
func TestDeleteRepository(t *testing.T) {
path := "https://github.com/hanzoai/cd.git"
repoFixture.Given(t).
When().
Path(path).
Project("cd-project").
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, r.Repo, path)
}).
When().
Delete().
Then().
And(func(_ *Repository, err error) {
assert.EqualError(t, err, "repo not found")
})
}
func TestListRepoCLIOutput(t *testing.T) {
path := "https://github.com/hanzoai/cd.git"
repoFixture.Given(t).
When().
Path(path).
Project("cd-project").
Create().
Then().
AndCLIOutput(func(output string, _ error) {
assert.Equal(t, `Repository 'https://github.com/hanzoai/cd.git' added`, output)
}).
When().
List().
Then().
AndCLIOutput(func(output string, _ error) {
assert.Equal(t, `TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT
git https://github.com/hanzoai/cd.git false false false false Successful cd-project`, output)
})
}
func TestGetRepoCLIOutput(t *testing.T) {
path := "https://github.com/hanzoai/cd.git"
repoFixture.Given(t).
When().
Path(path).
Project("cd-project").
Create().
Then().
AndCLIOutput(func(output string, _ error) {
assert.Equal(t, `Repository 'https://github.com/hanzoai/cd.git' added`, output)
}).
When().
Get().
Then().
AndCLIOutput(func(output string, _ error) {
assert.Equal(t, `TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT
git https://github.com/hanzoai/cd.git false false false false Successful cd-project`, output)
})
}
func TestCreateRepoWithSameURLInTwoProjects(t *testing.T) {
ctx := projectFixture.Given(t)
ctx.Name("project-one").
When().
Create().
Then()
projectFixture.Given(t).
Name("project-two").
When().
Create().
Then()
path := "https://github.com/hanzoai/cd.git"
// Create repository in first project
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("project-one").
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, r.Repo, path)
})
// Create repository with same URL in second project
repoFixture.GivenWithSameState(ctx).
When().
Path(path).
Project("project-two").
Create().
Then().
And(func(r *Repository, _ error) {
assert.Equal(t, r.Repo, path)
})
}