diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-18 15:38:06 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2020-02-18 15:38:06 +0300 |
commit | 673ed0e161cc3d34729fd1dc1f04477f713b5f57 (patch) | |
tree | 6b05494ceb29135f9a62af06398c2e68398102d0 | |
parent | c7e283a96f8fe340304f399efc75ec2b62134dca (diff) |
Enable serverless domains source
-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) { |