diff options
author | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-27 11:42:58 +0300 |
---|---|---|
committer | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-27 11:42:58 +0300 |
commit | 5c43f84ea593cfdccfec4993d5baa300676fa946 (patch) | |
tree | e2e284b2fe21cced0e5b5007bca1d7ae46cc03ea /internal | |
parent | 89dfffbca7d5a21f002354909edb394b5001604a (diff) |
Initialize redirects config with default values
Diffstat (limited to 'internal')
-rw-r--r-- | internal/redirects/redirects.go | 7 | ||||
-rw-r--r-- | internal/redirects/redirects_test.go | 12 |
2 files changed, 6 insertions, 13 deletions
diff --git a/internal/redirects/redirects.go b/internal/redirects/redirects.go index ed3bc4b1..4add6537 100644 --- a/internal/redirects/redirects.go +++ b/internal/redirects/redirects.go @@ -35,7 +35,12 @@ const ( ) var ( - cfg = config.Redirects{} + cfg = config.Redirects{ + MaxConfigSize: defaultMaxConfigSize, + MaxPathSegments: defaultMaxPathSegments, + MaxRuleCount: defaultMaxRuleCount, + } + // ErrNoRedirect is the error thrown when a no redirect rule matches while trying to Rewrite URL. // This means that no redirect applies to the URL and you can fallback to serving actual content instead. ErrNoRedirect = errors.New("no redirect found") diff --git a/internal/redirects/redirects_test.go b/internal/redirects/redirects_test.go index a9891b90..d40b065b 100644 --- a/internal/redirects/redirects_test.go +++ b/internal/redirects/redirects_test.go @@ -12,14 +12,12 @@ import ( "github.com/stretchr/testify/require" netlifyRedirects "github.com/tj/go-redirects" - "gitlab.com/gitlab-org/gitlab-pages/internal/config" "gitlab.com/gitlab-org/gitlab-pages/internal/feature" "gitlab.com/gitlab-org/gitlab-pages/internal/testhelpers" ) func TestRedirectsRewrite(t *testing.T) { t.Setenv(feature.RedirectsPlaceholders.EnvVariable, "true") - setupRedirectsConfig() tests := []struct { name string @@ -140,7 +138,6 @@ func TestRedirectsRewrite(t *testing.T) { func TestRedirectsParseRedirects(t *testing.T) { ctx := context.Background() - setupRedirectsConfig() root, tmpDir := testhelpers.TmpDir(t) @@ -199,7 +196,6 @@ func TestRedirectsParseRedirects(t *testing.T) { func TestMaxRuleCount(t *testing.T) { root, tmpDir := testhelpers.TmpDir(t) - setupRedirectsConfig() err := os.WriteFile(path.Join(tmpDir, ConfigFile), []byte(strings.Repeat("/goto.html /target.html 301\n", cfg.MaxRuleCount-1)+ "/1000.html /target1000 301\n"+ @@ -230,11 +226,3 @@ func TestMaxRuleCount(t *testing.T) { t.Run("maxRuleCount matches", testFn("/1000.html", "/target1000", http.StatusMovedPermanently, nil)) t.Run("maxRuleCount+1 does not match", testFn("/1001.html", "", 0, ErrNoRedirect)) } - -func setupRedirectsConfig() { - SetConfig(config.Redirects{ - MaxConfigSize: defaultMaxConfigSize, - MaxPathSegments: defaultMaxPathSegments, - MaxRuleCount: defaultMaxRuleCount, - }) -} |