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:
authorJacob Vosmaer (GitLab) <jacob@gitlab.com>2017-03-24 15:51:03 +0300
committerJacob Vosmaer (GitLab) <jacob@gitlab.com>2017-03-24 15:51:03 +0300
commitf605420a3f1194079921f3661834d928ea8ada44 (patch)
tree065c6ed3f40fdc3c64d1a51da75c2b76a72e17f6
parentc0ca3bf6f09791e614482edec2898e2f74c27a88 (diff)
parentf46c0785d1f7f999ffbc2315d30e3474cae95d8a (diff)
Merge branch 'fix/clone-gitlab-test-only-once' into 'master'
Clone gitlab-test repo only once Closes #103 See merge request !94
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--internal/service/commit/isancestor_test.go33
-rw-r--r--internal/service/diff/commit_test.go6
-rw-r--r--internal/service/diff/testhelper_test.go25
-rw-r--r--internal/service/notifications/post_receive_test.go17
-rw-r--r--internal/service/ref/main_test.go27
-rw-r--r--internal/service/ref/refname_test.go9
-rw-r--r--internal/service/ref/refs_test.go9
-rw-r--r--internal/service/smarthttp/inforefs_test.go33
-rw-r--r--internal/testhelper/testhelper.go24
11 files changed, 87 insertions, 103 deletions
diff --git a/.gitignore b/.gitignore
index 79f5c2fe2..213ed2b0f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@
/_support/package/bin
/_support/bin
/internal/service/smarthttp/testdata
+/internal/testhelper/testdata
diff --git a/Makefile b/Makefile
index 7be15b539..c37c07c40 100644
--- a/Makefile
+++ b/Makefile
@@ -4,6 +4,7 @@ BUILD_DIR=$(shell pwd)
BIN_BUILD_DIR=${BUILD_DIR}/_build/bin
PKG_BUILD_DIR:=${BUILD_DIR}/_build/src/${PKG}
CMDS:=$(shell cd cmd && ls)
+TEST_REPO=internal/testhelper/testdata/data/gitlab-test.git
export GOPATH=${BUILD_DIR}/_build
export GO15VENDOREXPERIMENT=1
@@ -35,7 +36,10 @@ check-formatting: install-developer-tools
govendor-status: ${BUILD_DIR}/_build install-developer-tools
cd ${PKG_BUILD_DIR} && govendor status
-test: clean-build ${BUILD_DIR}/_build
+${TEST_REPO}:
+ git clone --bare https://gitlab.com/gitlab-org/gitlab-test.git $@
+
+test: clean-build ${TEST_REPO} ${BUILD_DIR}/_build
go test ${PKG}/...
lint: install-developer-tools
diff --git a/internal/service/commit/isancestor_test.go b/internal/service/commit/isancestor_test.go
index 64af9159e..ebd51090f 100644
--- a/internal/service/commit/isancestor_test.go
+++ b/internal/service/commit/isancestor_test.go
@@ -4,11 +4,12 @@ import (
"log"
"net"
"os"
- "os/exec"
"path"
"testing"
"time"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
+
"golang.org/x/net/context"
"google.golang.org/grpc"
@@ -18,27 +19,15 @@ import (
pb "gitlab.com/gitlab-org/gitaly-proto/go"
)
-const (
- scratchDir = "testdata/scratch"
- testRepoRoot = "testdata/data"
- testRepo = "group/test.git"
-)
+const scratchDir = "testdata/scratch"
-var serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+var (
+ serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+ testRepoPath = ""
+)
func TestMain(m *testing.M) {
- source := "https://gitlab.com/gitlab-org/gitlab-test.git"
- clonePath := path.Join(testRepoRoot, testRepo)
- if _, err := os.Stat(clonePath); err != nil {
- testCmd := exec.Command("git", "clone", "--bare", source, clonePath)
- testCmd.Stdout = os.Stdout
- testCmd.Stderr = os.Stderr
-
- if err := testCmd.Run(); err != nil {
- log.Printf("Test setup: failed to run %v", testCmd)
- os.Exit(-1)
- }
- }
+ testRepoPath = testhelper.GitlabTestRepoPath()
if err := os.MkdirAll(scratchDir, 0755); err != nil {
log.Fatal(err)
@@ -58,7 +47,7 @@ func TestMain(m *testing.M) {
func TestCommitIsAncestorFailure(t *testing.T) {
client := newCommitClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
queries := []struct {
Request *pb.CommitIsAncestorRequest
@@ -94,7 +83,7 @@ func TestCommitIsAncestorFailure(t *testing.T) {
},
{
Request: &pb.CommitIsAncestorRequest{
- Repository: &pb.Repository{Path: path.Join(testRepoRoot, testRepo, "2")},
+ Repository: &pb.Repository{Path: "fake-path"},
AncestorId: "b83d6e391c22777fca1ed3012fce84f633d7fed0",
ChildId: "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab",
},
@@ -114,7 +103,7 @@ func TestCommitIsAncestorFailure(t *testing.T) {
func TestCommitIsAncestorSuccess(t *testing.T) {
client := newCommitClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
queries := []struct {
Request *pb.CommitIsAncestorRequest
diff --git a/internal/service/diff/commit_test.go b/internal/service/diff/commit_test.go
index 1cf88283a..62a7a575b 100644
--- a/internal/service/diff/commit_test.go
+++ b/internal/service/diff/commit_test.go
@@ -25,7 +25,7 @@ func TestSuccessfulCommitDiffRequest(t *testing.T) {
defer server.Stop()
client := newDiffClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rightCommit := "57290e673a4c87f51294f5216672cbc58d485d25"
leftCommit := rightCommit + "~~" // Second ancestor of rightCommit
rpcRequest := &pb.CommitDiffRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
@@ -254,7 +254,7 @@ func TestFailedCommitDiffRequestWithEmptyCommit(t *testing.T) {
defer server.Stop()
client := newDiffClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rightCommit := ""
leftCommit := rightCommit + "~" // Parent of rightCommit
rpcRequest := &pb.CommitDiffRequest{Repository: repo, RightCommitId: rightCommit, LeftCommitId: leftCommit}
@@ -289,7 +289,7 @@ func TestFailedCommitDiffRequestWithNonExistentCommit(t *testing.T) {
defer server.Stop()
client := newDiffClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
nonExistentCommitID := "deadfacedeadfacedeadfacedeadfacedeadface"
leftCommit := nonExistentCommitID + "~" // Parent of rightCommit
rpcRequest := &pb.CommitDiffRequest{Repository: repo, RightCommitId: nonExistentCommitID, LeftCommitId: leftCommit}
diff --git a/internal/service/diff/testhelper_test.go b/internal/service/diff/testhelper_test.go
index b6af865bd..c2e7d36d8 100644
--- a/internal/service/diff/testhelper_test.go
+++ b/internal/service/diff/testhelper_test.go
@@ -3,30 +3,17 @@ package diff
import (
"log"
"os"
- "os/exec"
- "path"
"testing"
-)
-const (
- scratchDir = "testdata/scratch"
- testRepoRoot = "testdata/data"
- testRepo = "test.git"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
-func TestMain(m *testing.M) {
- source := "https://gitlab.com/gitlab-org/gitlab-test.git"
- clonePath := path.Join(testRepoRoot, testRepo)
- if _, err := os.Stat(clonePath); err != nil {
- testCmd := exec.Command("git", "clone", "--bare", source, clonePath)
- testCmd.Stdout = os.Stdout
- testCmd.Stderr = os.Stderr
+const scratchDir = "testdata/scratch"
- if err := testCmd.Run(); err != nil {
- log.Printf("Test setup: failed to run %v", testCmd)
- os.Exit(-1)
- }
- }
+var testRepoPath = ""
+
+func TestMain(m *testing.M) {
+ testRepoPath = testhelper.GitlabTestRepoPath()
if err := os.MkdirAll(scratchDir, 0755); err != nil {
log.Fatal(err)
diff --git a/internal/service/notifications/post_receive_test.go b/internal/service/notifications/post_receive_test.go
index 09449b10c..99cf90ec1 100644
--- a/internal/service/notifications/post_receive_test.go
+++ b/internal/service/notifications/post_receive_test.go
@@ -8,21 +8,24 @@ import (
"testing"
"time"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
+
pb "gitlab.com/gitlab-org/gitaly-proto/go"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
-const (
- scratchDir = "testdata/scratch"
- testRepoRoot = "testdata/data"
- testRepo = "group/test.git"
-)
+const scratchDir = "testdata/scratch"
-var serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+var (
+ serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+ testRepoPath = ""
+)
func TestMain(m *testing.M) {
+ testRepoPath = testhelper.GitlabTestRepoPath()
+
if err := os.MkdirAll(scratchDir, 0755); err != nil {
log.Fatal(err)
}
@@ -37,7 +40,7 @@ func TestSuccessfulPostReceive(t *testing.T) {
defer server.Stop()
client := newNotificationsClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.PostReceiveRequest{Repository: repo}
_, err := client.PostReceive(context.Background(), rpcRequest)
diff --git a/internal/service/ref/main_test.go b/internal/service/ref/main_test.go
index 1ffd2f76c..6ab98aa2d 100644
--- a/internal/service/ref/main_test.go
+++ b/internal/service/ref/main_test.go
@@ -4,38 +4,27 @@ import (
"log"
"net"
"os"
- "os/exec"
"path"
"testing"
"time"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
+
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
)
-const (
- scratchDir = "testdata/scratch"
- testRepoRoot = "testdata/data"
- testRepo = "group/test.git"
-)
+const scratchDir = "testdata/scratch"
-var serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+var (
+ serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+ testRepoPath = ""
+)
func TestMain(m *testing.M) {
- source := "https://gitlab.com/gitlab-org/gitlab-test.git"
- clonePath := path.Join(testRepoRoot, testRepo)
- if _, err := os.Stat(clonePath); err != nil {
- testCmd := exec.Command("git", "clone", "--bare", source, clonePath)
- testCmd.Stdout = os.Stdout
- testCmd.Stderr = os.Stderr
-
- if err := testCmd.Run(); err != nil {
- log.Printf("Test setup: failed to run %v", testCmd)
- os.Exit(-1)
- }
- }
+ testRepoPath = testhelper.GitlabTestRepoPath()
if err := os.MkdirAll(scratchDir, 0755); err != nil {
log.Fatal(err)
diff --git a/internal/service/ref/refname_test.go b/internal/service/ref/refname_test.go
index 4afe498a8..e0909b536 100644
--- a/internal/service/ref/refname_test.go
+++ b/internal/service/ref/refname_test.go
@@ -1,7 +1,6 @@
package ref
import (
- "path"
"testing"
"google.golang.org/grpc"
@@ -17,7 +16,7 @@ func TestFindRefNameSuccess(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindRefNameRequest{
Repository: repo,
CommitId: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
@@ -41,7 +40,7 @@ func TestFindRefNameEmptyCommit(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindRefNameRequest{
Repository: repo,
CommitId: "",
@@ -93,7 +92,7 @@ func TestFindRefNameInvalidPrefix(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindRefNameRequest{
Repository: repo,
CommitId: "0b4bc9a49b562e85de7cc9e834518ea6828729b9",
@@ -114,7 +113,7 @@ func TestFindRefNameInvalidObject(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindRefNameRequest{
Repository: repo,
CommitId: "dead1234dead1234dead1234dead1234dead1234",
diff --git a/internal/service/ref/refs_test.go b/internal/service/ref/refs_test.go
index 0a62aa678..83a774673 100644
--- a/internal/service/ref/refs_test.go
+++ b/internal/service/ref/refs_test.go
@@ -3,7 +3,6 @@ package ref
import (
"bytes"
"io"
- "path"
"testing"
pb "gitlab.com/gitlab-org/gitaly-proto/go"
@@ -26,7 +25,7 @@ func TestSuccessfulFindAllBranchNames(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindAllBranchNamesRequest{Repository: repo}
c, err := client.FindAllBranchNames(context.Background(), rpcRequest)
@@ -80,7 +79,7 @@ func TestSuccessfulFindAllTagNames(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindAllTagNamesRequest{Repository: repo}
c, err := client.FindAllTagNames(context.Background(), rpcRequest)
@@ -130,7 +129,7 @@ func TestEmptyFindAllTagNamesRequest(t *testing.T) {
}
func TestHeadReference(t *testing.T) {
- headRef, err := headReference(path.Join(testRepoRoot, testRepo))
+ headRef, err := headReference(testRepoPath)
if err != nil {
t.Fatal(err)
}
@@ -211,7 +210,7 @@ func TestSuccessfulFindDefaultBranchName(t *testing.T) {
defer server.Stop()
client := newRefClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.FindDefaultBranchNameRequest{Repository: repo}
r, err := client.FindDefaultBranchName(context.Background(), rpcRequest)
diff --git a/internal/service/smarthttp/inforefs_test.go b/internal/service/smarthttp/inforefs_test.go
index 9c6c06e0b..87b887785 100644
--- a/internal/service/smarthttp/inforefs_test.go
+++ b/internal/service/smarthttp/inforefs_test.go
@@ -6,12 +6,13 @@ import (
"log"
"net"
"os"
- "os/exec"
"path"
"strings"
"testing"
"time"
+ "gitlab.com/gitlab-org/gitaly/internal/testhelper"
+
pb "gitlab.com/gitlab-org/gitaly-proto/go"
pbhelper "gitlab.com/gitlab-org/gitaly-proto/go/helper"
@@ -21,27 +22,15 @@ import (
"google.golang.org/grpc/reflection"
)
-const (
- scratchDir = "testdata/scratch"
- testRepoRoot = "testdata/data"
- testRepo = "group/test.git"
-)
+const scratchDir = "testdata/scratch"
-var serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+var (
+ serverSocketPath = path.Join(scratchDir, "gitaly.sock")
+ testRepoPath = ""
+)
func TestMain(m *testing.M) {
- source := "https://gitlab.com/gitlab-org/gitlab-test.git"
- clonePath := path.Join(testRepoRoot, testRepo)
- if _, err := os.Stat(clonePath); err != nil {
- testCmd := exec.Command("git", "clone", "--bare", source, clonePath)
- testCmd.Stdout = os.Stdout
- testCmd.Stderr = os.Stderr
-
- if err := testCmd.Run(); err != nil {
- log.Printf("Test setup: failed to run %v", testCmd)
- os.Exit(-1)
- }
- }
+ testRepoPath = testhelper.GitlabTestRepoPath()
if err := os.MkdirAll(scratchDir, 0755); err != nil {
log.Fatal(err)
@@ -57,7 +46,7 @@ func TestSuccessfulInfoRefsUploadPack(t *testing.T) {
defer server.Stop()
client := newSmartHTTPClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.InfoRefsRequest{Repository: repo}
c, err := client.InfoRefsUploadPack(context.Background(), rpcRequest)
@@ -78,7 +67,7 @@ func TestSuccessfulInfoRefsReceivePack(t *testing.T) {
defer server.Stop()
client := newSmartHTTPClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, testRepo)}
+ repo := &pb.Repository{Path: testRepoPath}
rpcRequest := &pb.InfoRefsRequest{Repository: repo}
c, err := client.InfoRefsReceivePack(context.Background(), rpcRequest)
@@ -99,7 +88,7 @@ func TestFailureRepoNotFoundInfoRefsReceivePack(t *testing.T) {
defer server.Stop()
client := newSmartHTTPClient(t)
- repo := &pb.Repository{Path: path.Join(testRepoRoot, "another_repo")}
+ repo := &pb.Repository{Path: "testdata/data/another_repo"}
rpcRequest := &pb.InfoRefsRequest{Repository: repo}
c, err := client.InfoRefsReceivePack(context.Background(), rpcRequest)
diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go
index f515d9ff0..c6f9b0fe4 100644
--- a/internal/testhelper/testhelper.go
+++ b/internal/testhelper/testhelper.go
@@ -2,9 +2,15 @@ package testhelper
import (
"io/ioutil"
+ "log"
+ "os"
+ "path"
+ "runtime"
"testing"
)
+const testRepo = "testdata/data/gitlab-test.git"
+
// MustReadFile returns the content of a file or fails at once.
func MustReadFile(t *testing.T, filename string) []byte {
content, err := ioutil.ReadFile(filename)
@@ -14,3 +20,21 @@ func MustReadFile(t *testing.T, filename string) []byte {
return content
}
+
+// GitlabTestRepoPath returns the path to gitlab-test repo.
+// Tests should be calling this function instead of cloning the repo themselves.
+// Tests that involve modifications to the repo should copy/clone the repo
+// via the path returned from this function.
+func GitlabTestRepoPath() string {
+ _, currentFile, _, ok := runtime.Caller(0)
+ if !ok {
+ log.Fatal("Could not get caller info")
+ }
+
+ clonePath := path.Join(path.Dir(currentFile), testRepo)
+ if _, err := os.Stat(path.Join(clonePath, "objects")); err != nil {
+ log.Fatal("Test repo not found, did you run `make test`?")
+ }
+
+ return clonePath
+}