fix unit test failures in GitHub Actions caused by missing gitconfig
This commit is contained in:
parent
b5159281f9
commit
6fa86b407f
2 changed files with 14 additions and 5 deletions
4
.github/actions/check/Dockerfile
vendored
4
.github/actions/check/Dockerfile
vendored
|
@ -1,5 +1,7 @@
|
||||||
FROM golangci/golangci-lint:v1.12.5
|
FROM golangci/golangci-lint:v1.12.5
|
||||||
|
|
||||||
|
RUN apt-get install git
|
||||||
|
|
||||||
LABEL "com.github.actions.name"="Check"
|
LABEL "com.github.actions.name"="Check"
|
||||||
LABEL "com.github.actions.description"="Run static analysis and unit tests"
|
LABEL "com.github.actions.description"="Run static analysis and unit tests"
|
||||||
LABEL "com.github.actions.icon"="check-circle"
|
LABEL "com.github.actions.icon"="check-circle"
|
||||||
|
@ -9,4 +11,4 @@ COPY "entrypoint.sh" "/entrypoint.sh"
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
ENV GOFLAGS -mod=vendor
|
ENV GOFLAGS -mod=vendor
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
@ -14,6 +13,7 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestFindGitSlug(t *testing.T) {
|
func TestFindGitSlug(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ func TestFindGitRemoteURL(t *testing.T) {
|
||||||
|
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
gitConfig()
|
||||||
err = gitCmd("init", basedir)
|
err = gitCmd("init", basedir)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
|
|
||||||
|
@ -68,6 +69,8 @@ func TestGitFindRef(t *testing.T) {
|
||||||
defer os.RemoveAll(basedir)
|
defer os.RemoveAll(basedir)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
|
gitConfig()
|
||||||
|
|
||||||
for name, tt := range map[string]struct {
|
for name, tt := range map[string]struct {
|
||||||
Prepare func(t *testing.T, dir string)
|
Prepare func(t *testing.T, dir string)
|
||||||
Assert func(t *testing.T, ref string, err error)
|
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 {
|
func gitCmd(args ...string) error {
|
||||||
var stdout bytes.Buffer
|
|
||||||
cmd := exec.Command("git", args...)
|
cmd := exec.Command("git", args...)
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = ioutil.Discard
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if exitError, ok := err.(*exec.ExitError); ok {
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
|
|
Loading…
Reference in a new issue