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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Hiltunen <shiltunen@gitlab.com>2021-03-30 10:48:32 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-03-30 10:48:32 +0300
commit79003389aa5098a6ef37e73298cafbad4d9e6b79 (patch)
tree4d827eb9267e688639a2b48cf573625477a5a4b8
parent4fc9376104a85ddaed9e32b4809330c08ba244fb (diff)
parent99e0c9ca0274318bec389fb1a47bc4d9b9101280 (diff)
Merge branch 'ps-rm-config-wiki' into 'master'
Remove config.Config from wiki package See merge request gitlab-org/gitaly!3314
-rw-r--r--internal/gitaly/service/wiki/delete_page_test.go26
-rw-r--r--internal/gitaly/service/wiki/find_file_test.go28
-rw-r--r--internal/gitaly/service/wiki/find_page_test.go76
-rw-r--r--internal/gitaly/service/wiki/get_all_pages_test.go47
-rw-r--r--internal/gitaly/service/wiki/get_page_versions_test.go25
-rw-r--r--internal/gitaly/service/wiki/list_pages_test.go27
-rw-r--r--internal/gitaly/service/wiki/testhelper_test.go111
-rw-r--r--internal/gitaly/service/wiki/update_page_test.go25
-rw-r--r--internal/gitaly/service/wiki/write_page_test.go45
9 files changed, 171 insertions, 239 deletions
diff --git a/internal/gitaly/service/wiki/delete_page_test.go b/internal/gitaly/service/wiki/delete_page_test.go
index 8b5ea726e..0ed152cfb 100644
--- a/internal/gitaly/service/wiki/delete_page_test.go
+++ b/internal/gitaly/service/wiki/delete_page_test.go
@@ -7,25 +7,22 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
- wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiDeletePageRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- wikiRepo := localrepo.New(git.NewExecCommandFactory(config.Config), wikiRepoProto, config.Config)
+
+ wikiRepo := localrepo.New(git.NewExecCommandFactory(cfg), wikiRepoProto, cfg)
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
pageName := "A talé of two wikis"
authorID := int32(1)
@@ -85,16 +82,11 @@ func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
}
}
-func TestFailedWikiDeletePageDueToValidations(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testFailedWikiDeletePageDueToValidations(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
commitDetails := &gitalypb.WikiCommitDetails{
Name: []byte("Ahmad Sherif"),
diff --git a/internal/gitaly/service/wiki/find_file_test.go b/internal/gitaly/service/wiki/find_file_test.go
index b2d90c680..effa48ab4 100644
--- a/internal/gitaly/service/wiki/find_file_test.go
+++ b/internal/gitaly/service/wiki/find_file_test.go
@@ -10,26 +10,21 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiFindFileRequest(t *testing.T) {
- _, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiFindFileRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ _, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
committerName := "Scrooge McDuck"
committerEmail := "scrooge@mcduck.com"
- storagePath := testhelper.GitlabTestStoragePath()
- sandboxWikiPath := filepath.Join(storagePath, "find-file-sandbox")
+ sandboxWikiPath := filepath.Join(cfg.Storages[0].Path, "find-file-sandbox")
testhelper.MustRunCommand(t, nil, "git", "clone", wikiRepoPath, sandboxWikiPath)
defer os.RemoveAll(sandboxWikiPath)
@@ -154,16 +149,11 @@ func TestSuccessfulWikiFindFileRequest(t *testing.T) {
}
}
-func TestFailedWikiFindFileDueToValidation(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testFailedWikiFindFileDueToValidation(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
testCases := []struct {
desc string
@@ -221,6 +211,8 @@ func drainWikiFindFileResponse(c gitalypb.WikiService_WikiFindFileClient) error
}
func readFullResponseFromWikiFindFileClient(t *testing.T, c gitalypb.WikiService_WikiFindFileClient) (fullResponse *gitalypb.WikiFindFileResponse) {
+ t.Helper()
+
for {
resp, err := c.Recv()
if err == io.EOF {
diff --git a/internal/gitaly/service/wiki/find_page_test.go b/internal/gitaly/service/wiki/find_page_test.go
index cee56b111..81f5e1c2a 100644
--- a/internal/gitaly/service/wiki/find_page_test.go
+++ b/internal/gitaly/service/wiki/find_page_test.go
@@ -8,21 +8,18 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiFindPageRequest(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiFindPageRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
page1Name := "Home Pagé"
page2Name := "Instálling/Step 133-b"
@@ -33,14 +30,14 @@ func TestSuccessfulWikiFindPageRequest(t *testing.T) {
page7Name := "~Tilde in filename"
page8Name := "~!/Tilde with invalid user"
- page1Commit := createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page1Name})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page2Name})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page3Name})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page4Name, content: []byte("f\xFCr")})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page5Name, forceContentEmpty: true})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page6Name})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page7Name})
- page8Commit := createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page8Name})
+ page1Commit := createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page1Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page2Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page3Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page4Name, content: []byte("f\xFCr")})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page5Name, forceContentEmpty: true})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page6Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page7Name})
+ page8Commit := createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page8Name})
latestCommit := page8Commit
testCases := []struct {
@@ -257,16 +254,11 @@ func TestSuccessfulWikiFindPageRequest(t *testing.T) {
}
}
-func TestSuccessfulWikiFindPageSameTitleDifferentPathRequest(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiFindPageSameTitleDifferentPathRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
page1Name := "page1"
page1Content := []byte("content " + page1Name)
@@ -275,8 +267,8 @@ func TestSuccessfulWikiFindPageSameTitleDifferentPathRequest(t *testing.T) {
page2Path := "foo/" + page2Name
page2Content := []byte("content " + page2Name)
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page1Name, content: page1Content})
- page2Commit := createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page2Path, content: page2Content})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page1Name, content: page1Content})
+ page2Commit := createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page2Path, content: page2Content})
testCases := []struct {
desc string
@@ -375,15 +367,11 @@ func TestSuccessfulWikiFindPageSameTitleDifferentPathRequest(t *testing.T) {
}
func TestFailedWikiFindPageDueToValidation(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ cfg := testcfg.Build(t)
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, nil)
testCases := []struct {
desc string
@@ -445,14 +433,11 @@ func readFullWikiPageFromWikiFindPageClient(t *testing.T, c gitalypb.WikiService
}
func TestInvalidWikiFindPageRequestRevision(t *testing.T) {
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
+ cfg := testcfg.Build(t)
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, nil)
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
ctx, cancel := testhelper.Context()
@@ -469,8 +454,8 @@ func TestInvalidWikiFindPageRequestRevision(t *testing.T) {
testhelper.RequireGrpcError(t, err, codes.InvalidArgument)
}
-func TestSuccessfulWikiFindPageRequestWithTrailers(t *testing.T) {
- wikiRepo, worktreePath, cleanupFn := gittest.InitRepoWithWorktree(t)
+func testSuccessfulWikiFindPageRequestWithTrailers(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, worktreePath, cleanupFn := gittest.InitRepoWithWorktreeAtStorage(t, cfg.Storages[0])
defer cleanupFn()
committerName := "Scróoge McDuck" // Include UTF-8 to ensure encoding is handled
@@ -481,15 +466,10 @@ func TestSuccessfulWikiFindPageRequestWithTrailers(t *testing.T) {
"-c", fmt.Sprintf("user.email=%s", committerEmail),
"commit", "--allow-empty", "-m", "master branch, empty commit")
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
page1Name := "Home Pagé"
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page1Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, worktreePath, createWikiPageOpts{title: page1Name})
testhelper.MustRunCommand(t, nil, "git", "-C", worktreePath,
"-c", fmt.Sprintf("user.name=%s", committerName),
diff --git a/internal/gitaly/service/wiki/get_all_pages_test.go b/internal/gitaly/service/wiki/get_all_pages_test.go
index 092a66fd1..c05e55c6f 100644
--- a/internal/gitaly/service/wiki/get_all_pages_test.go
+++ b/internal/gitaly/service/wiki/get_all_pages_test.go
@@ -6,27 +6,21 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
- "gitlab.com/gitlab-org/gitaly/internal/storage"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiGetAllPagesRequest(t *testing.T) {
+func testSuccessfulWikiGetAllPagesRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
-
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ client := setupWikiService(t, cfg, rubySrv)
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- expectedPages := createTestWikiPages(t, locator, client, wikiRepo)
+ expectedPages := createTestWikiPages(t, cfg, client, wikiRepo, wikiRepoPath)
testcases := []struct {
desc string
@@ -68,21 +62,15 @@ func TestSuccessfulWikiGetAllPagesRequest(t *testing.T) {
}
}
-func TestWikiGetAllPagesSorting(t *testing.T) {
+func testWikiGetAllPagesSorting(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
-
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ client := setupWikiService(t, cfg, rubySrv)
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- expectedPages := createTestWikiPages(t, locator, client, wikiRepo)
+ expectedPages := createTestWikiPages(t, cfg, client, wikiRepo, wikiRepoPath)
testcasesWithSorting := []struct {
desc string
@@ -180,13 +168,8 @@ func TestWikiGetAllPagesSorting(t *testing.T) {
}
}
-func TestFailedWikiGetAllPagesDueToValidation(t *testing.T) {
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+func testFailedWikiGetAllPagesDueToValidation(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ client := setupWikiService(t, cfg, rubySrv)
testCases := []struct {
desc string
@@ -209,13 +192,13 @@ func TestFailedWikiGetAllPagesDueToValidation(t *testing.T) {
}
}
-func createTestWikiPages(t *testing.T, locator storage.Locator, client gitalypb.WikiServiceClient, wikiRepo *gitalypb.Repository) []*gitalypb.WikiPage {
+func createTestWikiPages(t *testing.T, cfg config.Cfg, client gitalypb.WikiServiceClient, wikiRepo *gitalypb.Repository, wikiRepoPath string) []*gitalypb.WikiPage {
page1Name := "Page 1"
page2Name := "Page 2"
page3Name := "Page 3"
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page2Name, forceContentEmpty: true})
- createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page1Name})
- page3Commit := createTestWikiPage(t, locator, client, wikiRepo, createWikiPageOpts{title: page3Name})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page2Name, forceContentEmpty: true})
+ createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page1Name})
+ page3Commit := createTestWikiPage(t, cfg, client, wikiRepo, wikiRepoPath, createWikiPageOpts{title: page3Name})
expectedPage1 := &gitalypb.WikiPage{
Version: &gitalypb.WikiPageVersion{Commit: page3Commit, Format: "markdown"},
Title: []byte(page1Name),
diff --git a/internal/gitaly/service/wiki/get_page_versions_test.go b/internal/gitaly/service/wiki/get_page_versions_test.go
index fcd4bfd46..71c3bb317 100644
--- a/internal/gitaly/service/wiki/get_page_versions_test.go
+++ b/internal/gitaly/service/wiki/get_page_versions_test.go
@@ -10,25 +10,22 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
-func TestWikiGetPageVersionsRequest(t *testing.T) {
- wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+func testWikiGetPageVersionsRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
+ client := setupWikiService(t, cfg, rubySrv)
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
- pageTitle := "WikiGétPageVersions"
+ const pageTitle = "WikiGétPageVersions"
content := bytes.Repeat([]byte("Mock wiki page content"), 10000)
writeWikiPage(t, client, wikiRepo, createWikiPageOpts{title: pageTitle, content: content})
@@ -110,21 +107,17 @@ func TestWikiGetPageVersionsRequest(t *testing.T) {
}
}
-func TestWikiGetPageVersionsPaginationParams(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testWikiGetPageVersionsPaginationParams(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
+ client := setupWikiService(t, cfg, rubySrv)
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ const pageTitle = "WikiGetPageVersions"
- pageTitle := "WikiGetPageVersions"
content := []byte("page content")
writeWikiPage(t, client, wikiRepo, createWikiPageOpts{title: pageTitle, content: content})
diff --git a/internal/gitaly/service/wiki/list_pages_test.go b/internal/gitaly/service/wiki/list_pages_test.go
index 621f3a4e2..2ff8ffdae 100644
--- a/internal/gitaly/service/wiki/list_pages_test.go
+++ b/internal/gitaly/service/wiki/list_pages_test.go
@@ -6,25 +6,21 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
-func TestSuccessfulWikiListPagesRequest(t *testing.T) {
+func testSuccessfulWikiListPagesRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
+ client := setupWikiService(t, cfg, rubySrv)
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
-
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- expectedPages := createTestWikiPages(t, locator, client, wikiRepo)
+ expectedPages := createTestWikiPages(t, cfg, client, wikiRepo, wikiRepoPath)
testcases := []struct {
desc string
@@ -68,21 +64,16 @@ func TestSuccessfulWikiListPagesRequest(t *testing.T) {
}
}
-func TestWikiListPagesSorting(t *testing.T) {
+func testWikiListPagesSorting(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+ wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- expectedPages := createTestWikiPages(t, locator, client, wikiRepo)
+ expectedPages := createTestWikiPages(t, cfg, client, wikiRepo, wikiRepoPath)
testcasesWithSorting := []struct {
desc string
diff --git a/internal/gitaly/service/wiki/testhelper_test.go b/internal/gitaly/service/wiki/testhelper_test.go
index 1174a3442..e55a212ee 100644
--- a/internal/gitaly/service/wiki/testhelper_test.go
+++ b/internal/gitaly/service/wiki/testhelper_test.go
@@ -4,19 +4,21 @@ import (
"bytes"
"io/ioutil"
"os"
- "path/filepath"
- "strings"
+ "reflect"
+ "runtime"
"testing"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
+ "gitlab.com/gitlab-org/gitaly/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/storage"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
@@ -29,10 +31,7 @@ type createWikiPageOpts struct {
forceContentEmpty bool
}
-var (
- mockPageContent = bytes.Repeat([]byte("Mock wiki page content"), 10000)
- rubyServer *rubyserver.Server
-)
+var mockPageContent = bytes.Repeat([]byte("Mock wiki page content"), 10000)
func TestMain(m *testing.M) {
os.Exit(testMain(m))
@@ -52,42 +51,77 @@ func testMain(m *testing.M) int {
defer os.RemoveAll(tempDir)
hooks.Override = tempDir + "/hooks"
- config.Config.InternalSocketDir = tempDir + "/sock"
- rubyServer = rubyserver.New(config.Config)
- if err := rubyServer.Start(); err != nil {
- log.Error(err)
- return 1
+ return m.Run()
+}
+
+func TestWithRubySidecar(t *testing.T) {
+ cfg := testcfg.Build(t)
+
+ rubySrv := rubyserver.New(cfg)
+ require.NoError(t, rubySrv.Start())
+ t.Cleanup(rubySrv.Stop)
+
+ fs := []func(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server){
+ testSuccessfulWikiDeletePageRequest,
+ testFailedWikiDeletePageDueToValidations,
+ testSuccessfulWikiFindFileRequest,
+ testFailedWikiFindFileDueToValidation,
+ testSuccessfulWikiFindPageRequest,
+ testSuccessfulWikiFindPageSameTitleDifferentPathRequest,
+ testSuccessfulWikiFindPageRequestWithTrailers,
+ testSuccessfulWikiGetAllPagesRequest,
+ testWikiGetAllPagesSorting,
+ testFailedWikiGetAllPagesDueToValidation,
+ testWikiGetPageVersionsRequest,
+ testWikiGetPageVersionsPaginationParams,
+ testSuccessfulWikiListPagesRequest,
+ testWikiListPagesSorting,
+ testSuccessfulWikiUpdatePageRequest,
+ testFailedWikiUpdatePageDueToValidations,
+ testSuccessfulWikiWritePageRequest,
+ testFailedWikiWritePageDueToDuplicatePage,
+ testFailedWikiWritePageInPathDueToDuplicatePage,
}
- defer rubyServer.Stop()
+ for _, f := range fs {
+ t.Run(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), func(t *testing.T) {
+ f(t, cfg, rubySrv)
+ })
+ }
+}
- return m.Run()
+func setupWikiService(t testing.TB, cfg config.Cfg, rubySrv *rubyserver.Server) gitalypb.WikiServiceClient {
+ addr := runWikiServiceServer(t, config.NewLocator(cfg), rubySrv)
+ client := newWikiClient(t, addr)
+ return client
}
-func runWikiServiceServer(t *testing.T, locator storage.Locator) (func(), string) {
+func runWikiServiceServer(t testing.TB, locator storage.Locator, rubySrv *rubyserver.Server) string {
+ t.Helper()
+
srv := testhelper.NewServer(t, nil, nil)
- gitalypb.RegisterWikiServiceServer(srv.GrpcServer(), NewServer(rubyServer, locator))
+ gitalypb.RegisterWikiServiceServer(srv.GrpcServer(), NewServer(rubySrv, locator))
reflection.Register(srv.GrpcServer())
srv.Start(t)
+ t.Cleanup(srv.Stop)
- return srv.Stop, "unix://" + srv.Socket()
+ return "unix://" + srv.Socket()
}
-func newWikiClient(t *testing.T, serverSocketPath string) (gitalypb.WikiServiceClient, *grpc.ClientConn) {
- connOpts := []grpc.DialOption{
- grpc.WithInsecure(),
- }
- conn, err := grpc.Dial(serverSocketPath, connOpts...)
- if err != nil {
- t.Fatal(err)
- }
+func newWikiClient(t testing.TB, serverSocketPath string) gitalypb.WikiServiceClient {
+ t.Helper()
- return gitalypb.NewWikiServiceClient(conn), conn
+ conn, err := grpc.Dial(serverSocketPath, grpc.WithInsecure())
+ require.NoError(t, err)
+ t.Cleanup(func() { conn.Close() })
+ return gitalypb.NewWikiServiceClient(conn)
}
func writeWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *gitalypb.Repository, opts createWikiPageOpts) {
+ t.Helper()
+
var content []byte
if len(opts.content) == 0 && !opts.forceContentEmpty {
content = mockPageContent
@@ -131,6 +165,8 @@ func writeWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *gi
}
func updateWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *gitalypb.Repository, name string, content []byte) {
+ t.Helper()
+
commitDetails := &gitalypb.WikiCommitDetails{
Name: []byte("Ahmad Sherif"),
Email: []byte("ahmad@gitlab.com"),
@@ -159,19 +195,8 @@ func updateWikiPage(t *testing.T, client gitalypb.WikiServiceClient, wikiRepo *g
require.NoError(t, err)
}
-func setupWikiRepo(t *testing.T) (*gitalypb.Repository, string, func()) {
- relPath := strings.Join([]string{t.Name(), "wiki-test.git"}, "-")
- storagePath := testhelper.GitlabTestStoragePath()
- wikiRepoPath := filepath.Join(storagePath, relPath)
-
- testhelper.MustRunCommand(t, nil, "git", "init", "--bare", wikiRepoPath)
-
- wikiRepo := &gitalypb.Repository{
- StorageName: "default",
- RelativePath: relPath,
- }
-
- return wikiRepo, wikiRepoPath, func() { os.RemoveAll(wikiRepoPath) }
+func setupWikiRepo(t *testing.T, cfg config.Cfg) (*gitalypb.Repository, string, func()) {
+ return gittest.InitBareRepoAt(t, cfg.Storages[0])
}
func sendBytes(data []byte, chunkSize int, sender func([]byte) error) (int, error) {
@@ -191,16 +216,16 @@ func sendBytes(data []byte, chunkSize int, sender func([]byte) error) (int, erro
return i, nil
}
-func createTestWikiPage(t *testing.T, locator storage.Locator, client gitalypb.WikiServiceClient, wikiRepoProto *gitalypb.Repository, opts createWikiPageOpts) *gitalypb.GitCommit {
+func createTestWikiPage(t *testing.T, cfg config.Cfg, client gitalypb.WikiServiceClient, wikiRepoProto *gitalypb.Repository, wikiRepoPath string, opts createWikiPageOpts) *gitalypb.GitCommit {
+ t.Helper()
+
ctx, cancel := testhelper.Context()
defer cancel()
- wikiRepoPath, err := locator.GetRepoPath(wikiRepoProto)
- require.NoError(t, err)
writeWikiPage(t, client, wikiRepoProto, opts)
head1ID := testhelper.MustRunCommand(t, nil, "git", "-C", wikiRepoPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- wikiRepo := localrepo.New(git.NewExecCommandFactory(config.Config), wikiRepoProto, config.Config)
+ wikiRepo := localrepo.New(git.NewExecCommandFactory(cfg), wikiRepoProto, cfg)
pageCommit, err := wikiRepo.ReadCommit(ctx, git.Revision(head1ID))
require.NoError(t, err, "look up git commit after writing a wiki page")
@@ -208,6 +233,8 @@ func createTestWikiPage(t *testing.T, locator storage.Locator, client gitalypb.W
}
func requireWikiPagesEqual(t *testing.T, expectedPage *gitalypb.WikiPage, actualPage *gitalypb.WikiPage) {
+ t.Helper()
+
// require.Equal doesn't display a proper diff when either expected/actual has a field
// with large data (RawData in our case), so we compare file attributes and content separately.
expectedContent := expectedPage.GetRawData()
diff --git a/internal/gitaly/service/wiki/update_page_test.go b/internal/gitaly/service/wiki/update_page_test.go
index ddb254d5b..01ff5b232 100644
--- a/internal/gitaly/service/wiki/update_page_test.go
+++ b/internal/gitaly/service/wiki/update_page_test.go
@@ -8,25 +8,21 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
- wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiUpdatePageRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- wikiRepo := localrepo.New(git.NewExecCommandFactory(config.Config), wikiRepoProto, config.Config)
+ wikiRepo := localrepo.New(git.NewExecCommandFactory(cfg), wikiRepoProto, cfg)
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
writeWikiPage(t, client, wikiRepoProto, createWikiPageOpts{title: "Instálling Gitaly", content: []byte("foobar")})
@@ -114,16 +110,11 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
}
}
-func TestFailedWikiUpdatePageDueToValidations(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testFailedWikiUpdatePageDueToValidations(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
writeWikiPage(t, client, wikiRepo, createWikiPageOpts{title: "Installing Gitaly", content: []byte("foobar")})
diff --git a/internal/gitaly/service/wiki/write_page_test.go b/internal/gitaly/service/wiki/write_page_test.go
index d48102010..8a1464086 100644
--- a/internal/gitaly/service/wiki/write_page_test.go
+++ b/internal/gitaly/service/wiki/write_page_test.go
@@ -8,25 +8,22 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"google.golang.org/grpc/codes"
)
-func TestSuccessfulWikiWritePageRequest(t *testing.T) {
- wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+func testSuccessfulWikiWritePageRequest(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- wikiRepo := localrepo.New(git.NewExecCommandFactory(config.Config), wikiRepoProto, config.Config)
+ wikiRepo := localrepo.New(git.NewExecCommandFactory(cfg), wikiRepoProto, cfg)
ctx, cancel := testhelper.Context()
defer cancel()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
authorID := int32(1)
authorUserName := []byte("ahmad")
@@ -117,16 +114,11 @@ func TestSuccessfulWikiWritePageRequest(t *testing.T) {
}
}
-func TestFailedWikiWritePageDueToDuplicatePage(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testFailedWikiWritePageDueToDuplicatePage(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
pageName := "Installing Gitaly"
content := []byte("Mock wiki page content")
@@ -163,16 +155,11 @@ func TestFailedWikiWritePageDueToDuplicatePage(t *testing.T) {
testhelper.ProtoEqual(t, expectedResponse, response)
}
-func TestFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T) {
- wikiRepo, _, cleanupFunc := setupWikiRepo(t)
+func testFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T, cfg config.Cfg, rubySrv *rubyserver.Server) {
+ wikiRepo, _, cleanupFunc := setupWikiRepo(t, cfg)
defer cleanupFunc()
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ client := setupWikiService(t, cfg, rubySrv)
pageName := "foo/Installing Gitaly"
content := []byte("Mock wiki page content")
@@ -212,12 +199,8 @@ func TestFailedWikiWritePageInPathDueToDuplicatePage(t *testing.T) {
func TestFailedWikiWritePageDueToValidations(t *testing.T) {
wikiRepo := &gitalypb.Repository{}
- locator := config.NewLocator(config.Config)
- stop, serverSocketPath := runWikiServiceServer(t, locator)
- defer stop()
-
- client, conn := newWikiClient(t, serverSocketPath)
- defer conn.Close()
+ cfg := testcfg.Build(t)
+ client := setupWikiService(t, cfg, nil)
commitDetails := &gitalypb.WikiCommitDetails{
Name: []byte("Ahmad Sherif"),