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 <jacob@gitlab.com>2017-04-07 17:53:05 +0300
committerJacob Vosmaer <jacob@gitlab.com>2017-04-11 17:24:58 +0300
commitc8d9d4c52724b2d28bf049bb934235641289b297 (patch)
treeb888e689b799d4c6db17ea229b8a248fd11f2a8a /internal/helper/repo_test.go
parent731b45600a31f4fdc060b4c931b9820bbfe6ecf1 (diff)
Use config.StoragePath in GetRepoPath
Diffstat (limited to 'internal/helper/repo_test.go')
-rw-r--r--internal/helper/repo_test.go106
1 files changed, 88 insertions, 18 deletions
diff --git a/internal/helper/repo_test.go b/internal/helper/repo_test.go
index c23619aa9..788ad2e10 100644
--- a/internal/helper/repo_test.go
+++ b/internal/helper/repo_test.go
@@ -3,31 +3,101 @@ package helper
import (
"testing"
+ "gitlab.com/gitlab-org/gitaly/internal/config"
+
pb "gitlab.com/gitlab-org/gitaly-proto/go"
+
+ "github.com/stretchr/testify/assert"
)
-func TestGetRepoPathWithNilRepo(t *testing.T) {
- if _, err := GetRepoPath(nil); err == nil {
- t.Errorf("Expected an error, got nil")
+func TestGetRepoPath(t *testing.T) {
+ defer func(oldStorages []config.Storage) {
+ config.Config.Storages = oldStorages
+ }(config.Config.Storages)
+
+ exampleStorages := []config.Storage{
+ {Name: "default", Path: "/home/git/repositories1"},
+ {Name: "other", Path: "/home/git/repositories2"},
+ {Name: "third", Path: "/home/git/repositories3"},
}
-}
-func TestGetRepoPathWithEmptyPath(t *testing.T) {
- repo := &pb.Repository{Path: ""}
- if _, err := GetRepoPath(repo); err == nil {
- t.Errorf("Expected an error, got nil")
+ testCases := []struct {
+ desc string
+ storages []config.Storage
+ repo *pb.Repository
+ path string
+ notFound bool
+ }{
+ {
+ desc: "storages configured but only repo.Path is provided",
+ storages: exampleStorages,
+ repo: &pb.Repository{Path: "/foo/bar.git"},
+ path: "/foo/bar.git",
+ },
+ {
+ desc: "storages configured, storage name not known, repo.Path provided",
+ storages: exampleStorages,
+ repo: &pb.Repository{Path: "/foo/bar.git", StorageName: "does not exist", RelativePath: "foobar.git"},
+ path: "/foo/bar.git",
+ },
+ {
+ desc: "no storages configured, repo.Path provided",
+ repo: &pb.Repository{Path: "/foo/bar.git", StorageName: "does not exist", RelativePath: "foobar.git"},
+ path: "/foo/bar.git",
+ },
+ {
+ desc: "storages configured, no repo.Path",
+ storages: exampleStorages,
+ repo: &pb.Repository{StorageName: "default", RelativePath: "bazqux.git"},
+ path: "/home/git/repositories1/bazqux.git",
+ },
+ {
+ desc: "storage configured, storage name match, repo.Path provided",
+ storages: exampleStorages,
+ repo: &pb.Repository{Path: "/foo/bar.git", StorageName: "default", RelativePath: "bazqux.git"},
+ path: "/home/git/repositories1/bazqux.git",
+ },
+ {
+ desc: "no storage config, repo.Path provided",
+ repo: &pb.Repository{Path: "/foo/bar.git", StorageName: "default", RelativePath: "bazqux.git"},
+ path: "/foo/bar.git",
+ },
+ {
+ desc: "no storage config, storage name provided, no repo.Path",
+ repo: &pb.Repository{StorageName: "does not exist", RelativePath: "foobar.git"},
+ notFound: true,
+ },
+ {
+ desc: "no storage config, nil repo",
+ notFound: true,
+ },
+ {
+ desc: "storage config provided, empty repo",
+ storages: exampleStorages,
+ repo: &pb.Repository{},
+ notFound: true,
+ },
+ {
+ desc: "no storage config, empty repo",
+ repo: &pb.Repository{},
+ notFound: true,
+ },
}
-}
-func TestGetRepoPathWithValidRepo(t *testing.T) {
- expectedPath := "/path/to/repo"
- repo := &pb.Repository{Path: expectedPath}
+ for _, tc := range testCases {
+ config.Config.Storages = tc.storages
+ path, err := GetRepoPath(tc.repo)
- path, err := GetRepoPath(repo)
- if err != nil {
- t.Errorf("Expected a nil error, got %v", err)
- }
- if path != expectedPath {
- t.Errorf("Expected path to be %q, got %q", expectedPath, path)
+ if tc.notFound {
+ assert.Error(t, err, tc.desc)
+ continue
+ }
+
+ if err != nil {
+ assert.NoError(t, err, tc.desc)
+ continue
+ }
+
+ assert.Equal(t, tc.path, path, tc.desc)
}
}