From 6fa86b407f03fc5ba1c921c4f4e20ab643b53768 Mon Sep 17 00:00:00 2001 From: Casey Lee Date: Tue, 28 May 2019 09:47:40 -0700 Subject: [PATCH] fix unit test failures in GitHub Actions caused by missing gitconfig --- .github/actions/check/Dockerfile | 4 +++- common/git_test.go | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/actions/check/Dockerfile b/.github/actions/check/Dockerfile index 699fdd0..b1100c7 100644 --- a/.github/actions/check/Dockerfile +++ b/.github/actions/check/Dockerfile @@ -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"] \ No newline at end of file +ENTRYPOINT ["/entrypoint.sh"] diff --git a/common/git_test.go b/common/git_test.go index d159510..70fea2d 100644 --- a/common/git_test.go +++ b/common/git_test.go @@ -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 {