diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/source/domains.go | 16 | ||||
-rw-r--r-- | internal/source/domains_test.go | 31 |
2 files changed, 46 insertions, 1 deletions
diff --git a/internal/source/domains.go b/internal/source/domains.go index 79357766..b70b59e6 100644 --- a/internal/source/domains.go +++ b/internal/source/domains.go @@ -2,6 +2,7 @@ package source import ( "errors" + "regexp" "time" log "github.com/sirupsen/logrus" @@ -13,7 +14,10 @@ import ( "gitlab.com/gitlab-org/gitlab-pages/internal/source/gitlab" ) -var gitlabSourceConfig gitlabsourceconfig.GitlabSourceConfig +var ( + gitlabSourceConfig gitlabsourceconfig.GitlabSourceConfig + serverlessDomainRegex = regexp.MustCompile(`^[^.]+-[[:xdigit:]]{2}a1[[:xdigit:]]{10}f2[[:xdigit:]]{2}[[:xdigit:]]+-?.*`) +) func init() { // Start watching the config file for domains that will use the new `gitlab` source, @@ -78,6 +82,10 @@ func (d *Domains) source(domain string) Source { return d.disk } + if IsServerlessDomain(domain) { + return d.gitlab + } + for _, name := range gitlabSourceConfig.Domains.Enabled { if domain == name { return d.gitlab @@ -98,3 +106,9 @@ func (d *Domains) source(domain string) Source { return d.disk } + +// IsServerlessDomain checks if a domain requested is a serverless domain we +// need to handle differently +func IsServerlessDomain(domain string) bool { + return serverlessDomainRegex.MatchString(domain) +} diff --git a/internal/source/domains_test.go b/internal/source/domains_test.go index d639b02d..9afde412 100644 --- a/internal/source/domains_test.go +++ b/internal/source/domains_test.go @@ -109,6 +109,37 @@ func TestGetDomain(t *testing.T) { require.Nil(t, domain) require.NoError(t, err) }) + + t.Run("when requesting a serverless domain", func(t *testing.T) { + testDomain := "func-aba1aabbccddeef2abaabbcc.serverless.gitlab.io" + + newSource := NewMockSource() + newSource.On("GetDomain", testDomain). + Return(&domain.Domain{Name: testDomain}, nil). + Once() + defer newSource.AssertExpectations(t) + + domains := &Domains{ + disk: disk.New(), + gitlab: newSource, + } + + domains.GetDomain(testDomain) + }) +} + +func TestIsServerlessDomain(t *testing.T) { + t.Run("when a domain is serverless domain", func(t *testing.T) { + require.True(t, IsServerlessDomain("some-function-aba1aabbccddeef2abaabbcc.serverless.gitlab.io")) + }) + + t.Run("when a domain is serverless domain with environment", func(t *testing.T) { + require.True(t, IsServerlessDomain("some-function-aba1aabbccddeef2abaabbcc-testing.serverless.gitlab.io")) + }) + + t.Run("when a domain is not a serverless domain", func(t *testing.T) { + require.False(t, IsServerlessDomain("somedomain.gitlab.io")) + }) } func TestGetDomainWithIncrementalrolloutOfGitLabSource(t *testing.T) { |