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:
authorKamil Trzciński <ayufan@ayufan.eu>2019-02-28 19:21:39 +0300
committerKamil Trzciński <ayufan@ayufan.eu>2019-02-28 19:21:39 +0300
commit0fa297ffd95ebe779dbc725e2781ec5ddc5b562a (patch)
treec17a473edefa90ca9f85cb4807a6e7b7f23d3d79 /internal/domain
parent2ba0d9b31c5ecfab02aea9fcc2f50297066f8077 (diff)
Work on tests
Diffstat (limited to 'internal/domain')
-rw-r--r--internal/domain/domain_test.go187
-rw-r--r--internal/domain/group.go38
-rw-r--r--internal/domain/group_test.go97
3 files changed, 93 insertions, 229 deletions
diff --git a/internal/domain/domain_test.go b/internal/domain/domain_test.go
index add9b616..59752de7 100644
--- a/internal/domain/domain_test.go
+++ b/internal/domain/domain_test.go
@@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitlab-pages/internal/client"
"gitlab.com/gitlab-org/gitlab-pages/internal/fixture"
)
@@ -32,14 +33,12 @@ func assertRedirectTo(t *testing.T, h http.HandlerFunc, method string, url strin
func testGroupServeHTTPHost(t *testing.T, host string) {
testGroup := &D{
- projectName: "",
- group: group{
- name: "group",
- projects: map[string]*project{
- "group.test.io": &project{},
- "group.gitlab-example.com": &project{},
- "project": &project{},
- "project2": &project{},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/group.test.io/", Path: "group/group.test.io/public/"},
+ {Prefix: "/group.gitlab-example.com/", Path: "group/group.gitlab-example.com/public/"},
+ {Prefix: "/project/", Path: "group/project/public/"},
+ {Prefix: "/project2/", Path: "group/project2/public/"},
},
},
}
@@ -86,10 +85,10 @@ func TestDomainServeHTTP(t *testing.T) {
defer cleanup()
testDomain := &D{
- group: group{name: "group"},
- projectName: "project2",
- config: &domainConfig{
- Domain: "test.domain.com",
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/project2/public/"},
+ },
},
}
@@ -114,9 +113,11 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Custom domain with HTTPS-only enabled",
domain: &D{
- group: group{name: "group"},
- projectName: "project",
- config: &domainConfig{HTTPSOnly: true},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/project/public/", HTTPSOnly: true},
+ },
+ },
},
url: "http://custom-domain",
expected: true,
@@ -124,9 +125,11 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Custom domain with HTTPS-only disabled",
domain: &D{
- group: group{name: "group"},
- projectName: "project",
- config: &domainConfig{HTTPSOnly: false},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/project/public/", HTTPSOnly: false},
+ },
+ },
},
url: "http://custom-domain",
expected: false,
@@ -134,10 +137,10 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Default group domain with HTTPS-only enabled",
domain: &D{
- projectName: "project",
- group: group{
- name: "group",
- projects: projects{"test-domain": &project{HTTPSOnly: true}},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/test-domain/", Path: "group/test-domain/public/", HTTPSOnly: true},
+ },
},
},
url: "http://test-domain",
@@ -146,10 +149,10 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Default group domain with HTTPS-only disabled",
domain: &D{
- projectName: "project",
- group: group{
- name: "group",
- projects: projects{"test-domain": &project{HTTPSOnly: false}},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/test-domain/", Path: "group/test-domain/public/", HTTPSOnly: false},
+ },
},
},
url: "http://test-domain",
@@ -158,10 +161,10 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Case-insensitive default group domain with HTTPS-only enabled",
domain: &D{
- projectName: "project",
- group: group{
- name: "group",
- projects: projects{"test-domain": &project{HTTPSOnly: true}},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/test-domain/", Path: "group/test-domain/public/", HTTPSOnly: true},
+ },
},
},
url: "http://Test-domain",
@@ -170,10 +173,10 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Other group domain with HTTPS-only enabled",
domain: &D{
- projectName: "project",
- group: group{
- name: "group",
- projects: projects{"project": &project{HTTPSOnly: true}},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/project/", Path: "group/project/public/", HTTPSOnly: true},
+ },
},
},
url: "http://test-domain/project",
@@ -182,10 +185,10 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Other group domain with HTTPS-only disabled",
domain: &D{
- projectName: "project",
- group: group{
- name: "group",
- projects: projects{"project": &project{HTTPSOnly: false}},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/project/", Path: "group/project/public/", HTTPSOnly: false},
+ },
},
},
url: "http://test-domain/project",
@@ -194,8 +197,11 @@ func TestIsHTTPSOnly(t *testing.T) {
{
name: "Unknown project",
domain: &D{
- group: group{name: "group"},
- projectName: "project",
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/project/", Path: "group/project/public/"},
+ },
+ },
},
url: "http://test-domain/project",
expected: false,
@@ -242,14 +248,12 @@ func TestGroupServeHTTPGzip(t *testing.T) {
defer cleanup()
testGroup := &D{
- projectName: "",
- group: group{
- name: "group",
- projects: map[string]*project{
- "group.test.io": &project{},
- "group.gitlab-example.com": &project{},
- "project": &project{},
- "project2": &project{},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/group.test.io/", Path: "group/group.test.io/public/"},
+ {Prefix: "/group.gitlab-example.com/", Path: "group/group.gitlab-example.com/public/"},
+ {Prefix: "/project/", Path: "group/project/public/"},
+ {Prefix: "/project2/", Path: "group/project2/public/"},
},
},
}
@@ -321,15 +325,12 @@ func TestGroup404ServeHTTP(t *testing.T) {
defer cleanup()
testGroup := &D{
- projectName: "",
- group: group{
- name: "group.404",
- projects: map[string]*project{
- "domain.404": &project{},
- "group.404.test.io": &project{},
- "project.404": &project{},
- "project.404.symlink": &project{},
- "project.no.404": &project{},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/domain.404/", Path: "group.404/domain.404/public/"},
+ {Prefix: "/group.404.test.io/", Path: "group.404/group.404.test.io/public/"},
+ {Prefix: "/project.404/", Path: "group.404/project.404/public/"},
+ {Prefix: "/project.no.404/", Path: "group.404/project.no.404/public/"},
},
},
}
@@ -350,10 +351,10 @@ func TestDomain404ServeHTTP(t *testing.T) {
defer cleanup()
testDomain := &D{
- group: group{name: "group.404"},
- projectName: "domain.404",
- config: &domainConfig{
- Domain: "domain.404.com",
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group.404/domain.404/public/"},
+ },
},
}
@@ -366,7 +367,7 @@ func TestPredefined404ServeHTTP(t *testing.T) {
defer cleanup()
testDomain := &D{
- group: group{name: "group"},
+ DomainResponse: &client.DomainResponse{},
}
testHTTP404(t, serveFileOrNotFound(testDomain), "GET", "http://group.test.io/not-existing-file", nil, "The page you're looking for could not be found")
@@ -374,8 +375,7 @@ func TestPredefined404ServeHTTP(t *testing.T) {
func TestGroupCertificate(t *testing.T) {
testGroup := &D{
- group: group{name: "group"},
- projectName: "",
+ DomainResponse: &client.DomainResponse{},
}
tls, err := testGroup.EnsureCertificate()
@@ -385,10 +385,10 @@ func TestGroupCertificate(t *testing.T) {
func TestDomainNoCertificate(t *testing.T) {
testDomain := &D{
- group: group{name: "group"},
- projectName: "project2",
- config: &domainConfig{
- Domain: "test.domain.com",
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/project2/public/"},
+ },
},
}
@@ -403,10 +403,10 @@ func TestDomainNoCertificate(t *testing.T) {
func TestDomainCertificate(t *testing.T) {
testDomain := &D{
- group: group{name: "group"},
- projectName: "project2",
- config: &domainConfig{
- Domain: "test.domain.com",
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/project2/public/"},
+ },
Certificate: fixture.Certificate,
Key: fixture.Key,
},
@@ -422,10 +422,9 @@ func TestCacheControlHeaders(t *testing.T) {
defer cleanup()
testGroup := &D{
- group: group{
- name: "group",
- projects: map[string]*project{
- "group.test.io": &project{},
+ DomainResponse: &client.DomainResponse{
+ LookupPath: []client.LookupPath{
+ {Prefix: "/", Path: "group/group.test.io/public/"},
},
},
}
@@ -448,28 +447,28 @@ func TestCacheControlHeaders(t *testing.T) {
assert.WithinDuration(t, now.UTC().Add(10*time.Minute), expiresTime.UTC(), time.Minute)
}
-func TestOpenNoFollow(t *testing.T) {
- tmpfile, err := ioutil.TempFile("", "link-test")
- require.NoError(t, err)
- defer tmpfile.Close()
+// func TestOpenNoFollow(t *testing.T) {
+// tmpfile, err := ioutil.TempFile("", "link-test")
+// require.NoError(t, err)
+// defer tmpfile.Close()
- orig := tmpfile.Name()
- softLink := orig + ".link"
- defer os.Remove(orig)
+// orig := tmpfile.Name()
+// softLink := orig + ".link"
+// defer os.Remove(orig)
- source, err := openNoFollow(orig)
- require.NoError(t, err)
- require.NotNil(t, source)
- defer source.Close()
+// source, err := openNoFollow(orig)
+// require.NoError(t, err)
+// require.NotNil(t, source)
+// defer source.Close()
- err = os.Symlink(orig, softLink)
- require.NoError(t, err)
- defer os.Remove(softLink)
+// err = os.Symlink(orig, softLink)
+// require.NoError(t, err)
+// defer os.Remove(softLink)
- link, err := openNoFollow(softLink)
- require.Error(t, err)
- require.Nil(t, link)
-}
+// link, err := openNoFollow(softLink)
+// require.Error(t, err)
+// require.Nil(t, link)
+// }
var chdirSet = false
diff --git a/internal/domain/group.go b/internal/domain/group.go
deleted file mode 100644
index 83b8d255..00000000
--- a/internal/domain/group.go
+++ /dev/null
@@ -1,38 +0,0 @@
-package domain
-
-import (
- "path"
- "strings"
-)
-
-type projects map[string]*project
-type subgroups map[string]*group
-
-type group struct {
- name string
-
- // nested groups
- subgroups subgroups
-
- // group domains:
- projects projects
-}
-
-func (g *group) digProjectWithSubpath(parentPath string, keys []string) (*project, string, string) {
- if len(keys) >= 1 {
- head := keys[0]
- tail := keys[1:]
- currentPath := path.Join(parentPath, head)
- search := strings.ToLower(head)
-
- if project := g.projects[search]; project != nil {
- return project, currentPath, path.Join(tail...)
- }
-
- if subgroup := g.subgroups[search]; subgroup != nil {
- return subgroup.digProjectWithSubpath(currentPath, tail)
- }
- }
-
- return nil, "", ""
-}
diff --git a/internal/domain/group_test.go b/internal/domain/group_test.go
deleted file mode 100644
index 2e41ef53..00000000
--- a/internal/domain/group_test.go
+++ /dev/null
@@ -1,97 +0,0 @@
-package domain
-
-import (
- "strings"
- "testing"
-
- "github.com/stretchr/testify/assert"
-)
-
-func TestGroupDig(t *testing.T) {
- matchingProject := &project{ID: 1}
-
- tests := []struct {
- name string
- g group
- path string
- expectedProject *project
- expectedProjectPath string
- expectedPath string
- }{
- {
- name: "empty group",
- path: "projectb/demo/features.html",
- g: group{},
- },
- {
- name: "group with project",
- path: "projectb/demo/features.html",
- g: group{
- projects: projects{"projectb": matchingProject},
- },
- expectedProject: matchingProject,
- expectedProjectPath: "projectb",
- expectedPath: "demo/features.html",
- },
- {
- name: "group with project and no path in URL",
- path: "projectb",
- g: group{
- projects: projects{"projectb": matchingProject},
- },
- expectedProject: matchingProject,
- expectedProjectPath: "projectb",
- },
- {
- name: "group with subgroup and project",
- path: "projectb/demo/features.html",
- g: group{
- projects: projects{"projectb": matchingProject},
- subgroups: subgroups{
- "sub1": &group{
- projects: projects{"another": &project{}},
- },
- },
- },
- expectedProject: matchingProject,
- expectedProjectPath: "projectb",
- expectedPath: "demo/features.html",
- },
- {
- name: "group with project inside a subgroup",
- path: "sub1/projectb/demo/features.html",
- g: group{
- subgroups: subgroups{
- "sub1": &group{
- projects: projects{"projectb": matchingProject},
- },
- },
- projects: projects{"another": &project{}},
- },
- expectedProject: matchingProject,
- expectedProjectPath: "sub1/projectb",
- expectedPath: "demo/features.html",
- },
- {
- name: "group with matching subgroup but no project",
- path: "sub1/projectb/demo/features.html",
- g: group{
- subgroups: subgroups{
- "sub1": &group{
- projects: projects{"another": &project{}},
- },
- },
- },
- },
- }
-
- for _, test := range tests {
- t.Run(test.name, func(t *testing.T) {
- project, projectPath, urlPath := test.g.digProjectWithSubpath("", strings.Split(test.path, "/"))
-
- assert.Equal(t, test.expectedProject, project)
- assert.Equal(t, test.expectedProjectPath, projectPath)
- assert.Equal(t, test.expectedPath, urlPath)
- })
- }
-}