mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-11 17:50:58 +00:00
fix unit test failures in GitHub Actions caused by missing gitconfig
This commit is contained in:
parent
d145281fc4
commit
113ebda3ff
2 changed files with 14 additions and 5 deletions
|
@ -1,7 +1,6 @@
|
|||
package common
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
@ -14,6 +13,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
||||
func TestFindGitSlug(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
@ -51,6 +51,7 @@ func TestFindGitRemoteURL(t *testing.T) {
|
|||
|
||||
assert.Nil(err)
|
||||
|
||||
gitConfig()
|
||||
err = gitCmd("init", basedir)
|
||||
assert.Nil(err)
|
||||
|
||||
|
@ -68,6 +69,8 @@ func TestGitFindRef(t *testing.T) {
|
|||
defer os.RemoveAll(basedir)
|
||||
assert.NoError(t, err)
|
||||
|
||||
gitConfig()
|
||||
|
||||
for name, tt := range map[string]struct {
|
||||
Prepare func(t *testing.T, dir string)
|
||||
Assert func(t *testing.T, ref string, err error)
|
||||
|
@ -143,11 +146,15 @@ func TestGitFindRef(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func gitConfig() {
|
||||
_ = gitCmd("config","--global","user.email","test@test.com")
|
||||
_ = gitCmd("config","--global","user.name","Unit Test")
|
||||
}
|
||||
|
||||
func gitCmd(args ...string) error {
|
||||
var stdout bytes.Buffer
|
||||
cmd := exec.Command("git", args...)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = ioutil.Discard
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if exitError, ok := err.(*exec.ExitError); ok {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue