Improvements to git integration test (#3466)

This commit is contained in:
Ethan Koenig 2018-02-06 01:27:24 -08:00 committed by Lauris BH
parent a89592d4ab
commit a2648281a0

View File

@ -13,6 +13,7 @@ import (
"net/http" "net/http"
"net/url" "net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"testing" "testing"
"time" "time"
@ -134,7 +135,7 @@ func TestGit(t *testing.T) {
//Setup key //Setup key
keyFile := filepath.Join(setting.AppDataPath, "my-testing-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) assert.NoError(t, err)
defer os.RemoveAll(keyFile) defer os.RemoveAll(keyFile)
defer os.RemoveAll(keyFile + ".pub") defer os.RemoveAll(keyFile + ".pub")
@ -152,13 +153,10 @@ func TestGit(t *testing.T) {
session.MakeRequest(t, req, http.StatusCreated) session.MakeRequest(t, req, http.StatusCreated)
//Setup ssh wrapper //Setup ssh wrapper
sshWrapper, err := ioutil.TempFile(setting.AppDataPath, "tmp-ssh-wrapper") os.Setenv("GIT_SSH_COMMAND",
sshWrapper.WriteString("#!/bin/sh\n\n") "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "+
sshWrapper.WriteString("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i \"" + filepath.Join(setting.AppWorkPath, keyFile) + "\" $* \n\n") filepath.Join(setting.AppWorkPath, keyFile))
err = sshWrapper.Chmod(os.ModePerm) os.Setenv("GIT_SSH_VARIANT", "ssh")
assert.NoError(t, err)
sshWrapper.Close()
defer os.RemoveAll(sshWrapper.Name())
//Setup clone folder //Setup clone folder
dstPath, err := ioutil.TempDir("", "repo-tmp-18") dstPath, err := ioutil.TempDir("", "repo-tmp-18")
@ -181,7 +179,7 @@ func TestGit(t *testing.T) {
}) })
//TODO get url from api //TODO get url from api
t.Run("Clone", func(t *testing.T) { 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.NoError(t, err)
assert.True(t, com.IsExist(filepath.Join(dstPath, "README.md"))) 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) { 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) { t.Run("PushCommit", func(t *testing.T) {
//Setup git LFS //Setup git LFS
_, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath) _, err = git.NewCommand("lfs").AddArguments("install").RunInDir(dstPath)