Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-06-09 16:39:27 +0300
committerNejc Habjan <nejc.habjan@siemens.com>2022-06-27 11:36:53 +0300
commit12ca83b790fdddbbfcf7c6b08aa9da79a3ab8f6d (patch)
tree0ea9b4650b7df3835e232806afbba7d285414b36 /internal
parent39b7e2c35b2f609623ae483ee3f607b3da42808e (diff)
Set up redirects config for unit tests
Diffstat (limited to 'internal')
-rw-r--r--internal/redirects/redirects_test.go22
1 files changed, 20 insertions, 2 deletions
diff --git a/internal/redirects/redirects_test.go b/internal/redirects/redirects_test.go
index c0df43c0..210e8fe0 100644
--- a/internal/redirects/redirects_test.go
+++ b/internal/redirects/redirects_test.go
@@ -12,12 +12,20 @@ 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"
)
+const (
+ defaultMaxConfigSize = 64 * 1024
+ defaultMaxPathSegments = 25
+ defaultMaxRuleCount = 1000
+)
+
func TestRedirectsRewrite(t *testing.T) {
t.Setenv(feature.RedirectsPlaceholders.EnvVariable, "true")
+ setupRedirectsConfig()
tests := []struct {
name string
@@ -138,6 +146,7 @@ func TestRedirectsRewrite(t *testing.T) {
func TestRedirectsParseRedirects(t *testing.T) {
ctx := context.Background()
+ setupRedirectsConfig()
root, tmpDir := testhelpers.TmpDir(t)
@@ -165,7 +174,7 @@ func TestRedirectsParseRedirects(t *testing.T) {
},
{
name: "Config file too big",
- redirectsFile: strings.Repeat("a", 2*cfg.Redirects.MaxConfigSize),
+ redirectsFile: strings.Repeat("a", 2*cfg.MaxConfigSize),
expectedRules: 0,
expectedErr: errFileTooLarge,
},
@@ -196,8 +205,9 @@ 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.Redirects.MaxRuleCount-1)+
+ err := os.WriteFile(path.Join(tmpDir, ConfigFile), []byte(strings.Repeat("/goto.html /target.html 301\n", cfg.MaxRuleCount-1)+
"/1000.html /target1000 301\n"+
"/1001.html /target1001 301\n",
), 0600)
@@ -226,3 +236,11 @@ 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,
+ })
+}