mirror of
https://codeberg.org/Codeberg/pages-server.git
synced 2025-05-12 13:07:50 +00:00
Support multiple canonical-domain-files
This commit is contained in:
parent
2410137438
commit
b2d40c5154
13 changed files with 238 additions and 128 deletions
75
server/upstream/domains_test.go
Normal file
75
server/upstream/domains_test.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package upstream
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestPageMainDomainGeneratesTheExpectedDomain(t *testing.T) {
|
||||
defaultOptions := Options{
|
||||
TargetOwner: "",
|
||||
TargetRepo: "",
|
||||
TargetBranch: "",
|
||||
TargetPath: "",
|
||||
Host: "",
|
||||
TryIndexPages: false,
|
||||
BranchTimestamp: time.Time{},
|
||||
appendTrailingSlash: false,
|
||||
redirectIfExists: "",
|
||||
ServeRaw: false,
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
targetOwner string
|
||||
targetRepo string
|
||||
domainSuffix string
|
||||
expectedDomain string
|
||||
}{
|
||||
{"foo", "", ".localhost.mock.directory", "foo.localhost.mock.directory"},
|
||||
{"foo", "pages", ".localhost.mock.directory", "foo.localhost.mock.directory"},
|
||||
{"foo", "bar", ".localhost.mock.directory", "foo.localhost.mock.directory/bar"},
|
||||
} {
|
||||
options := defaultOptions
|
||||
options.TargetOwner = tc.targetOwner
|
||||
options.TargetRepo = tc.targetRepo
|
||||
|
||||
actualDomain := options.pageMainDomain(tc.domainSuffix)
|
||||
|
||||
assert.Equal(t, tc.expectedDomain, actualDomain)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeDomainEntries(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
domain string
|
||||
}{
|
||||
{"abc.com"},
|
||||
{"ABC.com"},
|
||||
{" ABC.com"},
|
||||
{"ABC.com "},
|
||||
{" ABC.com "},
|
||||
{"http://ABC.com"},
|
||||
{"https://ABC.com"},
|
||||
} {
|
||||
actualDomains := normalizeDomainEntries(tc.domain)
|
||||
expectedDomains := []string{"abc.com"}
|
||||
|
||||
assert.Equal(t, expectedDomains, actualDomains)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
domains string
|
||||
expectedDomains []string
|
||||
}{
|
||||
{"", []string{}},
|
||||
{"ABC.com", []string{"abc.com"}},
|
||||
{"ABC.com\nhttps://example.com", []string{"abc.com", "example.com"}},
|
||||
{"\n\nABC.com\n\nhttps://example.com\n", []string{"abc.com", "example.com"}},
|
||||
} {
|
||||
actualDomains := normalizeDomainEntries(tc.domains)
|
||||
|
||||
assert.Equal(t, tc.expectedDomains, actualDomains)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue