fix unit test failures in GitHub Actions caused by missing gitconfig

This commit is contained in:
Casey Lee 2019-05-28 09:47:40 -07:00
parent b5159281f9
commit 6fa86b407f
No known key found for this signature in database
GPG Key ID: 1899120ECD0A1784
2 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,7 @@
FROM golangci/golangci-lint:v1.12.5
RUN apt-get install git
LABEL "com.github.actions.name"="Check"
LABEL "com.github.actions.description"="Run static analysis and unit tests"
LABEL "com.github.actions.icon"="check-circle"
@ -9,4 +11,4 @@ COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh
ENV GOFLAGS -mod=vendor
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]

View File

@ -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 {