From a2648281a044f33da5492c9d7aaddb6523b65f3a Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Tue, 6 Feb 2018 01:27:24 -0800 Subject: [PATCH] Improvements to git integration test (#3466) --- integrations/git_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/integrations/git_test.go b/integrations/git_test.go index 1ab558d7b..49f75c4a4 100644 --- a/integrations/git_test.go +++ b/integrations/git_test.go @@ -13,6 +13,7 @@ import ( "net/http" "net/url" "os" + "os/exec" "path/filepath" "testing" "time" @@ -134,7 +135,7 @@ func TestGit(t *testing.T) { //Setup key keyFile := filepath.Join(setting.AppDataPath, "my-testing-key") - _, _, err := com.ExecCmd("ssh-keygen", "-f", keyFile, "-t", "rsa", "-N", "") + err := exec.Command("ssh-keygen", "-f", keyFile, "-t", "rsa", "-N", "").Run() assert.NoError(t, err) defer os.RemoveAll(keyFile) defer os.RemoveAll(keyFile + ".pub") @@ -152,13 +153,10 @@ func TestGit(t *testing.T) { session.MakeRequest(t, req, http.StatusCreated) //Setup ssh wrapper - sshWrapper, err := ioutil.TempFile(setting.AppDataPath, "tmp-ssh-wrapper") - sshWrapper.WriteString("#!/bin/sh\n\n") - sshWrapper.WriteString("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i \"" + filepath.Join(setting.AppWorkPath, keyFile) + "\" $* \n\n") - err = sshWrapper.Chmod(os.ModePerm) - assert.NoError(t, err) - sshWrapper.Close() - defer os.RemoveAll(sshWrapper.Name()) + os.Setenv("GIT_SSH_COMMAND", + "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+ + filepath.Join(setting.AppWorkPath, keyFile)) + os.Setenv("GIT_SSH_VARIANT", "ssh") //Setup clone folder dstPath, err := ioutil.TempDir("", "repo-tmp-18") @@ -181,7 +179,7 @@ func TestGit(t *testing.T) { }) //TODO get url from api t.Run("Clone", func(t *testing.T) { - _, err = git.NewCommand("clone").AddArguments("--config", "core.sshCommand="+filepath.Join(setting.AppWorkPath, sshWrapper.Name()), u.String(), dstPath).Run() + _, err = git.NewCommand("clone").AddArguments(u.String(), dstPath).Run() assert.NoError(t, err) assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md"))) }) @@ -196,8 +194,6 @@ func TestGit(t *testing.T) { }) }) t.Run("LFS", func(t *testing.T) { - os.Setenv("GIT_SSH_COMMAND", filepath.Join(setting.AppWorkPath, sshWrapper.Name())) //TODO remove when fixed https://github.com/git-lfs/git-lfs/issues/2215 - defer os.Unsetenv("GIT_SSH_COMMAND") t.Run("PushCommit", func(t *testing.T) { //Setup git LFS _, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)