diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2020-04-08 15:36:21 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2020-04-08 15:36:21 +0300 |
commit | 0afd877056bbb9bcdbd9d2fbb8220bea751783e9 (patch) | |
tree | 3019463ff79e8182e7850968c8844094fd3b8cb5 | |
parent | 9b176ae5af1de6f1e90827776d0cc0cd30c18919 (diff) | |
parent | b84b90697a2f81438fe051909db0a00db038a28c (diff) |
Merge branch 'fix-failing-tests' into 'master'
Overwrite git global config and fix partial clone tests
See merge request gitlab-org/gitaly!2008
-rw-r--r-- | internal/testhelper/testdata/home/.gitconfig | 3 | ||||
-rw-r--r-- | internal/testhelper/testhelper.go | 31 | ||||
-rw-r--r-- | ruby/spec/support/helpers/gitlab_shell_helper.rb | 3 | ||||
-rw-r--r-- | ruby/spec/support/helpers/testdata/home/.gitconfig | 3 |
4 files changed, 40 insertions, 0 deletions
diff --git a/internal/testhelper/testdata/home/.gitconfig b/internal/testhelper/testdata/home/.gitconfig new file mode 100644 index 000000000..29ace58d5 --- /dev/null +++ b/internal/testhelper/testdata/home/.gitconfig @@ -0,0 +1,3 @@ +[user] + email = you@example.com + name = Your Name diff --git a/internal/testhelper/testhelper.go b/internal/testhelper/testhelper.go index dbf2b3497..d0003e1e1 100644 --- a/internal/testhelper/testhelper.go +++ b/internal/testhelper/testhelper.go @@ -70,6 +70,7 @@ func Configure() { for _, f := range []func() error{ ConfigureRuby, + ConfigureGit, config.Validate, } { if err := f(); err != nil { @@ -280,6 +281,32 @@ func GetLocalhostListener(t TB) (net.Listener, string) { return l, addr } +// ConfigureGit configures git for test purpose +func ConfigureGit() error { + _, currentFile, _, ok := runtime.Caller(0) + if !ok { + return fmt.Errorf("could not get caller info") + } + + goenvCmd := exec.Command("go", "env", "GOCACHE") + goCacheBytes, err := goenvCmd.Output() + goCache := strings.TrimSpace(string(goCacheBytes)) + if err != nil { + return err + } + + // set GOCACHE env to current go cache location, otherwise if it's default it would be overwritten by setting HOME + err = os.Setenv("GOCACHE", goCache) + if err != nil { + return err + } + + testHome := filepath.Join(filepath.Dir(currentFile), "testdata/home") + + // overwrite HOME env variable so user global .gitconfig doesn't influence tests + return os.Setenv("HOME", testHome) +} + // ConfigureRuby configures Ruby settings for test purposes at run time. func ConfigureRuby() error { if dir := os.Getenv("GITALY_TEST_RUBY_DIR"); len(dir) > 0 { @@ -564,6 +591,10 @@ func GitObjectMustNotExist(t TB, repoPath, sha string) { func gitObjectExists(t TB, repoPath, sha string, exists bool) { cmd := exec.Command("git", "-C", repoPath, "cat-file", "-e", sha) + cmd.Env = []string{ + "GIT_ALLOW_PROTOCOL=", // To prevent partial clone reaching remote repo over SSH + } + if exists { require.NoError(t, cmd.Run(), "checking for object should succeed") return diff --git a/ruby/spec/support/helpers/gitlab_shell_helper.rb b/ruby/spec/support/helpers/gitlab_shell_helper.rb index b38b6ae62..7c1aafb4d 100644 --- a/ruby/spec/support/helpers/gitlab_shell_helper.rb +++ b/ruby/spec/support/helpers/gitlab_shell_helper.rb @@ -5,6 +5,9 @@ TMP_DIR_NAME = 'tmp'.freeze TMP_DIR = File.join(GITALY_RUBY_DIR, TMP_DIR_NAME).freeze GITLAB_SHELL_DIR = File.join(TMP_DIR, 'gitlab-shell').freeze +# overwrite HOME env variable so user global .gitconfig doesn't influence tests +ENV["HOME"] = File.join(File.dirname(__FILE__), "/testdata/home") + module GitlabShellHelper def self.setup_gitlab_shell Gitlab.config.gitlab_shell.test_global_ivar_override(:path, GITLAB_SHELL_DIR) diff --git a/ruby/spec/support/helpers/testdata/home/.gitconfig b/ruby/spec/support/helpers/testdata/home/.gitconfig new file mode 100644 index 000000000..29ace58d5 --- /dev/null +++ b/ruby/spec/support/helpers/testdata/home/.gitconfig @@ -0,0 +1,3 @@ +[user] + email = you@example.com + name = Your Name |