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:
authorJaime Martinez <jmartinez@gitlab.com>2021-06-04 08:04:32 +0300
committerJaime Martinez <jmartinez@gitlab.com>2021-06-04 08:04:32 +0300
commitbe33a21c0184d1ff511fe6c88d23098bed439a71 (patch)
tree4bb9ae234a49101ff692ac48ff9b6340116a59b2
parentb9ba78cf43a14a4ca1c4893c7115eed56ce1b115 (diff)
Use table tests
-rw-r--r--internal/source/gitlab/gitlab_test.go64
1 files changed, 38 insertions, 26 deletions
diff --git a/internal/source/gitlab/gitlab_test.go b/internal/source/gitlab/gitlab_test.go
index b2c503f4..0848af88 100644
--- a/internal/source/gitlab/gitlab_test.go
+++ b/internal/source/gitlab/gitlab_test.go
@@ -109,33 +109,45 @@ func TestResolve(t *testing.T) {
})
}
-func TestResolveGroupFirst(t *testing.T) {
+// Test proves fix for https://gitlab.com/gitlab-org/gitlab-pages/-/issues/576
+func TestResolveLookupPathsOrderDoesNotMatter(t *testing.T) {
client := client.StubClient{File: "client/testdata/group-first.gitlab.io.json"}
source := Gitlab{client: client, enableDisk: true}
- t.Run("when requesting the group root project with root path", func(t *testing.T) {
- target := "https://group-first.gitlab.io:443/"
- request := httptest.NewRequest("GET", target, nil)
-
- response, err := source.Resolve(request)
- require.NoError(t, err)
-
- require.Equal(t, "/", response.LookupPath.Prefix)
- require.Equal(t, "some/path/group/", response.LookupPath.Path)
- require.Equal(t, "", response.SubPath)
- require.True(t, response.LookupPath.IsNamespaceProject)
- })
-
- t.Run("when requesting another project with path", func(t *testing.T) {
- target := "https://group-first.gitlab.io:443/my/second-project/index.html"
- request := httptest.NewRequest("GET", target, nil)
-
- response, err := source.Resolve(request)
- require.NoError(t, err)
-
- require.Equal(t, "/my/second-project/", response.LookupPath.Prefix)
- require.Equal(t, "some/path/to/project-2/", response.LookupPath.Path)
- require.Equal(t, "index.html", response.SubPath)
- require.False(t, response.LookupPath.IsNamespaceProject)
- })
+ tests := map[string]struct {
+ target string
+ expectedPrefix string
+ expectedPath string
+ expectedSubPath string
+ expectedIsNamespace bool
+ }{
+ "when requesting the group root project with root path": {
+ target: "https://group-first.gitlab.io:443/",
+ expectedPrefix: "/",
+ expectedPath: "some/path/group/",
+ expectedSubPath: "",
+ expectedIsNamespace: true,
+ },
+ "when requesting another project with path": {
+ target: "https://group-first.gitlab.io:443/my/second-project/index.html",
+ expectedPrefix: "/my/second-project/",
+ expectedPath: "some/path/to/project-2/",
+ expectedSubPath: "index.html",
+ expectedIsNamespace: false,
+ },
+ }
+
+ for name, test := range tests {
+ t.Run(name, func(t *testing.T) {
+ request := httptest.NewRequest("GET", test.target, nil)
+
+ response, err := source.Resolve(request)
+ require.NoError(t, err)
+
+ require.Equal(t, test.expectedPrefix, response.LookupPath.Prefix)
+ require.Equal(t, test.expectedPath, response.LookupPath.Path)
+ require.Equal(t, test.expectedSubPath, response.SubPath)
+ require.Equal(t, test.expectedIsNamespace, response.LookupPath.IsNamespaceProject)
+ })
+ }
}