Skip to content

Commit b573149

Browse files
authored
Merge pull request #335 from runatlantis/ggpsigntest
Fix tests when git config uses gpg signing.
2 parents 5a8230d + 4fcece0 commit b573149

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

server/events/pending_plan_finder_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestPendingPlanFinder_FindPlanCheckedIn(t *testing.T) {
184184
runCmd(t, repoDir, "git", "add", ".")
185185
runCmd(t, repoDir, "git", "config", "--local", "user.email", "[email protected]")
186186
runCmd(t, repoDir, "git", "config", "--local", "user.name", "atlantisbot")
187-
runCmd(t, repoDir, "git", "commit", "-m", "initial commit")
187+
runCmd(t, repoDir, "git", "commit", "--no-gpg-sign", "-m", "initial commit")
188188

189189
pf := &events.PendingPlanFinder{}
190190
actPlans, err := pf.Find(tmpDir)
@@ -193,6 +193,7 @@ func TestPendingPlanFinder_FindPlanCheckedIn(t *testing.T) {
193193
}
194194

195195
func runCmd(t *testing.T, dir string, name string, args ...string) string {
196+
t.Helper()
196197
cpCmd := exec.Command(name, args...)
197198
cpCmd.Dir = dir
198199
cpOut, err := cpCmd.CombinedOutput()

testing/assertions.go

+21-15
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
package testing
1515

1616
import (
17-
"fmt"
18-
"path/filepath"
19-
"runtime"
2017
"strings"
2118
"testing"
2219

@@ -27,19 +24,19 @@ import (
2724
// Assert fails the test if the condition is false.
2825
// Taken from https://github.com/benbjohnson/testing.
2926
func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
27+
tb.Helper()
3028
if !condition {
31-
_, file, line, _ := runtime.Caller(1)
32-
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
29+
errLog(tb, msg, v...)
3330
tb.FailNow()
3431
}
3532
}
3633

3734
// Ok fails the test if an err is not nil.
3835
// Taken from https://github.com/benbjohnson/testing.
3936
func Ok(tb testing.TB, err error) {
37+
tb.Helper()
4038
if err != nil {
41-
_, file, line, _ := runtime.Caller(1)
42-
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
39+
errLog(tb, "unexpected error: %s", err.Error())
4340
tb.FailNow()
4441
}
4542
}
@@ -49,19 +46,21 @@ func Ok(tb testing.TB, err error) {
4946
func Equals(tb testing.TB, exp, act interface{}) {
5047
tb.Helper()
5148
if diff := deep.Equal(exp, act); diff != nil {
52-
_, file, line, _ := runtime.Caller(1)
53-
tb.Fatalf("\033[31m%s:%d: %s\n\nexp: %s******\ngot: %s\033[39m\n", filepath.Base(file), line, diff, spew.Sdump(exp), spew.Sdump(act))
49+
errLog(tb, "%s\n\nexp: %s******\ngot: %s", diff, spew.Sdump(exp), spew.Sdump(act))
50+
tb.FailNow()
5451
}
5552
}
5653

5754
// ErrEquals fails the test if act is nil or act.Error() != exp
5855
func ErrEquals(tb testing.TB, exp string, act error) {
5956
tb.Helper()
6057
if act == nil {
61-
tb.Fatalf("exp err %q but err was nil\n", exp)
58+
errLog(tb, "exp err %q but err was nil\n", exp)
59+
tb.FailNow()
6260
}
6361
if act.Error() != exp {
64-
tb.Fatalf("exp err: %q but got: %q\n", exp, act.Error())
62+
errLog(tb, "exp err: %q but got: %q\n", exp, act.Error())
63+
tb.FailNow()
6564
}
6665
}
6766

@@ -70,21 +69,28 @@ func ErrEquals(tb testing.TB, exp string, act error) {
7069
func ErrContains(tb testing.TB, substr string, act error) {
7170
tb.Helper()
7271
if act == nil {
73-
tb.Fatalf("exp err to contain %q but err was nil", substr)
72+
errLog(tb, "exp err to contain %q but err was nil", substr)
73+
tb.FailNow()
7474
}
7575
if !strings.Contains(act.Error(), substr) {
76-
tb.Fatalf("exp err %q to contain %q", act.Error(), substr)
76+
errLog(tb, "exp err %q to contain %q", act.Error(), substr)
77+
tb.FailNow()
7778
}
7879
}
7980

8081
// Contains fails the test if the slice doesn't contain the expected element
8182
func Contains(tb testing.TB, exp interface{}, slice []string) {
83+
tb.Helper()
8284
for _, v := range slice {
8385
if v == exp {
8486
return
8587
}
8688
}
87-
_, file, line, _ := runtime.Caller(1)
88-
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\twas not in: %#v\033[39m\n\n", filepath.Base(file), line, exp, slice)
89+
errLog(tb, "exp: %#v\n\n\twas not in: %#v", exp, slice)
8990
tb.FailNow()
9091
}
92+
93+
func errLog(tb testing.TB, fmt string, args ...interface{}) {
94+
tb.Helper()
95+
tb.Logf("\033[31m"+fmt+"\033[39m", args...)
96+
}

0 commit comments

Comments
 (0)