Wildcards #2

Merged
PapaTutuWawa merged 17 commits from feat/wildcards into master 2024-01-11 20:04:50 +00:00
2 changed files with 9 additions and 8 deletions
Showing only changes of commit 40ce4e81a8 - Show all commits

View File

@ -127,6 +127,7 @@ func RepoFromPath(username, host, cname, path string, giteaClient *GiteaClient)
} }
pathParts := strings.Split(path, "/") pathParts := strings.Split(path, "/")
log.Debugf("reponame='%s' len(pathParts)='%d'", reponame, len(pathParts))
if reponame == "" && len(pathParts) > 1 { if reponame == "" && len(pathParts) > 1 {
log.Debugf("Trying repository %s", pathParts[0]) log.Debugf("Trying repository %s", pathParts[0])
modifiedPath := strings.Join(pathParts[1:], "/") modifiedPath := strings.Join(pathParts[1:], "/")

View File

@ -229,9 +229,9 @@ func TestPickingRepositoryValidCNAME(t *testing.T) {
log.SetLevel(log.DebugLevel) log.SetLevel(log.DebugLevel)
client := GiteaClient{ client := GiteaClient{
getRepository: func(username, repositoryName string) (Repository, error) { getRepository: func(username, repositoryName string) (Repository, error) {
if username == "example-user" && repositoryName == "example-user.pages.example.org" { if username == "example-user" && repositoryName == "example-user.local" {
return Repository{ return Repository{
Name: "example-user.pages.example.org", Name: "example-user.local",
}, nil }, nil
} else { } else {
t.Fatalf("Called with unknown repository %s", repositoryName) t.Fatalf("Called with unknown repository %s", repositoryName)
@ -239,14 +239,14 @@ func TestPickingRepositoryValidCNAME(t *testing.T) {
} }
}, },
hasBranch: func(username, repositoryName, branchName string) bool { hasBranch: func(username, repositoryName, branchName string) bool {
if username == "example-user" && repositoryName == "example-user.pages.example.org" && branchName == "pages" { if username == "example-user" && repositoryName == "example-user.local" && branchName == "pages" {
return true return true
} }
return false return false
}, },
GetFile: func(username, repositoryName, branch, path string, since *time.Time) ([]byte, bool, error) { GetFile: func(username, repositoryName, branch, path string, since *time.Time) ([]byte, bool, error) {
if username == "example-user" && repositoryName == "example-user.pages.example.org" && branch == "pages" && path == "CNAME" { if username == "example-user" && repositoryName == "example-user.local" && branch == "pages" && path == "CNAME" {
return []byte("example-user.local"), true, nil return []byte("example-user.local"), true, nil
} }
@ -261,11 +261,11 @@ func TestPickingRepositoryValidCNAME(t *testing.T) {
}, },
} }
repo, _, err := RepoFromPath("example-user", "example-user.pages.example.org", "example-user.local", "index.html", &client) repo, _, err := RepoFromPath("example-user", "example-user.local", "example-user.pages.example.org", "index.html", &client)
if err != nil { if err != nil {
t.Fatalf("Error returned: %v", err) t.Fatalf("Error returned: %v", err)
} }
if repo.Name != "example-user.pages.example.org" { if repo.Name != "example-user.local" {
t.Fatalf("Invalid repository name returned: %s", repo.Name) t.Fatalf("Invalid repository name returned: %s", repo.Name)
} }
} }
@ -313,7 +313,7 @@ func TestPickingRepositoryValidCNAMEWithTXTLookup(t *testing.T) {
}, },
} }
repo, _, err := RepoFromPath("example-user", "example-user.pages.example.org", "example-user.local", "index.html", &client) repo, _, err := RepoFromPath("example-user", "example-user.local", "example-user.pages.example.org", "index.html", &client)
if err != nil { if err != nil {
t.Fatalf("Error returned: %v", err) t.Fatalf("Error returned: %v", err)
} }
@ -364,7 +364,7 @@ func TestPickingRepositoryValidCNAMEWithTXTLookupAndSubdirectory(t *testing.T) {
}, },
} }
repo, _, err := RepoFromPath("example-user", "example-user.pages.example.org", "example-user.local", "blog/index.html", &client) repo, _, err := RepoFromPath("example-user", "example-user.local", "example-user.pages.example.org", "blog/index.html", &client)
if err != nil { if err != nil {
t.Fatalf("Error returned: %v", err) t.Fatalf("Error returned: %v", err)
} }