Skip to content

Commit

Permalink
fix unit test failures in GitHub Actions caused by missing gitconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
cplee committed May 28, 2019
1 parent b515928 commit 6fa86b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .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"
Expand All @@ -9,4 +11,4 @@ COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh

ENV GOFLAGS -mod=vendor
ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
15 changes: 11 additions & 4 deletions common/git_test.go
@@ -1,7 +1,6 @@
package common

import (
"bytes"
"fmt"
"io/ioutil"
"os"
Expand All @@ -14,6 +13,7 @@ import (
"github.com/stretchr/testify/require"
)


func TestFindGitSlug(t *testing.T) {
assert := assert.New(t)

Expand Down Expand Up @@ -51,6 +51,7 @@ func TestFindGitRemoteURL(t *testing.T) {

assert.Nil(err)

gitConfig()
err = gitCmd("init", basedir)
assert.Nil(err)

Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6fa86b4

Please sign in to comment.