From 954c00327ea1cb6d16c646ba3a97b5bd4f47170a Mon Sep 17 00:00:00 2001 From: Andrew Rynhard Date: Mon, 15 Oct 2018 13:26:58 -0700 Subject: [PATCH] fix(policy): unit test inline git config (#77) --- .../conventionalcommit_test.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pkg/policy/conventionalcommit/conventionalcommit_test.go b/pkg/policy/conventionalcommit/conventionalcommit_test.go index 8c0b8a5a..e5160159 100644 --- a/pkg/policy/conventionalcommit/conventionalcommit_test.go +++ b/pkg/policy/conventionalcommit/conventionalcommit_test.go @@ -1,6 +1,7 @@ package conventionalcommit import ( + "fmt" "io/ioutil" "log" "os" @@ -76,11 +77,11 @@ func TestInvalidConventionalCommitPolicy(t *testing.T) { func runCompliance() (*policy.Report, error) { g, err := git.NewGit() if err != nil { - return nil, err + return nil, fmt.Errorf("failed to open git: %v", err) } message, err := g.Message() if err != nil { - return nil, err + return nil, fmt.Errorf("failed to get commit message: %v", err) } c := &Conventional{} c.Types = []string{"type"} @@ -100,14 +101,6 @@ func initRepo() error { if err != nil { return err } - _, err = exec.Command("git", "config", "--global", "user.email", "'test@autonomy.io'").Output() - if err != nil { - return err - } - _, err = exec.Command("git", "config", "--global", "user.name", "test").Output() - if err != nil { - return err - } _, err = exec.Command("touch", "test").Output() if err != nil { return err @@ -118,13 +111,13 @@ func initRepo() error { } func createValidCommit() error { - _, err := exec.Command("git", "commit", "-m", "type(scope): description").Output() + _, err := exec.Command("git", "-c", "user.name='test'", "-c", "user.email='test@autonomy.io'", "commit", "-m", "type(scope): description").Output() return err } func createInvalidCommit() error { - _, err := exec.Command("git", "commit", "-m", "invalid commit").Output() + _, err := exec.Command("git", "-c", "user.name='test'", "-c", "user.email='test@autonomy.io'", "commit", "-m", "invalid commit").Output() return err }