git: one generator per app, multiple instances
this allows locking for access for each org
This commit is contained in:
@@ -29,53 +29,63 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGitClonePath(t *testing.T) {
|
||||
func TestGitClone(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
path string
|
||||
error string
|
||||
name string
|
||||
|
||||
repo string
|
||||
branch string
|
||||
remoteName string
|
||||
remoteUrl string
|
||||
}{
|
||||
{
|
||||
name: "git style clone",
|
||||
url: "gitea@src.opensuse.org:foo/bar",
|
||||
path: "bar",
|
||||
error: "",
|
||||
name: "Basic clone",
|
||||
repo: "pkgAclone",
|
||||
branch: "main",
|
||||
remoteName: "pkgA_main",
|
||||
remoteUrl: "/pkgA",
|
||||
},
|
||||
{
|
||||
name: "https:// style clone",
|
||||
url: "https://gitea@foo.bar:900/org/repo.git",
|
||||
path: "repo",
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "ssh:// style clone",
|
||||
url: "ssh://foo.bar/org/repo",
|
||||
path: "repo",
|
||||
error: "",
|
||||
},
|
||||
{
|
||||
name: "broken git style clone",
|
||||
url: "gi-tea@src.opensuse.org:foo/bar",
|
||||
path: "",
|
||||
error: "first path segment in URL cannot contain colon",
|
||||
name: "Remote branch is non-existent",
|
||||
repo: "pkgAclone",
|
||||
branch: "main_not_here",
|
||||
remoteName: "pkgA_main",
|
||||
remoteUrl: "/pkgA",
|
||||
},
|
||||
}
|
||||
|
||||
execPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := t.TempDir()
|
||||
os.Chdir(d)
|
||||
cmd := exec.Command("/usr/bin/bash", path.Join(execPath, "test_clone_setup.sh"))
|
||||
if _, err := cmd.Output(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
gh, err := AllocateGitWorkTree(d, "Test", "test@example.com")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
p, e := GitClonePathFromUrl(test.url)
|
||||
if e != nil {
|
||||
if test.error == "" || !strings.Contains(e.Error(), test.error) {
|
||||
t.Errorf("Expected .Contains('%s') but got '%s'", test.error, e.Error())
|
||||
}
|
||||
g, err := gh.CreateGitHandler("org", test.branch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if test.error != "" && e == nil {
|
||||
t.Fatal("expected error, but not none")
|
||||
|
||||
if err := g.GitClone(test.repo, test.branch, test.remoteName, "file://"+d+test.remoteUrl); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if e == nil && p != test.path {
|
||||
t.Error("Expected target path:", test.path, ", but got:", p)
|
||||
|
||||
id, err := g.GitBranchHead(test.repo, test.branch)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Fatal(id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user