diff --git a/server/events/pending_plan_finder_test.go b/server/events/pending_plan_finder_test.go index b513f64c01..b010cd38a3 100644 --- a/server/events/pending_plan_finder_test.go +++ b/server/events/pending_plan_finder_test.go @@ -184,7 +184,7 @@ func TestPendingPlanFinder_FindPlanCheckedIn(t *testing.T) { runCmd(t, repoDir, "git", "add", ".") runCmd(t, repoDir, "git", "config", "--local", "user.email", "atlantisbot@runatlantis.io") runCmd(t, repoDir, "git", "config", "--local", "user.name", "atlantisbot") - runCmd(t, repoDir, "git", "commit", "-m", "initial commit") + runCmd(t, repoDir, "git", "commit", "--no-gpg-sign", "-m", "initial commit") pf := &events.PendingPlanFinder{} actPlans, err := pf.Find(tmpDir) @@ -193,6 +193,7 @@ func TestPendingPlanFinder_FindPlanCheckedIn(t *testing.T) { } func runCmd(t *testing.T, dir string, name string, args ...string) string { + t.Helper() cpCmd := exec.Command(name, args...) cpCmd.Dir = dir cpOut, err := cpCmd.CombinedOutput() diff --git a/server/events/project_locker.go b/server/events/project_locker.go index b15ec4f75b..39c838ccab 100644 --- a/server/events/project_locker.go +++ b/server/events/project_locker.go @@ -63,7 +63,7 @@ func (p *DefaultProjectLocker) TryLock(log *logging.SimpleLogger, pull models.Pu } if !lockAttempt.LockAcquired && lockAttempt.CurrLock.Pull.Num != pull.Num { failureMsg := fmt.Sprintf( - "**Unable to run `plan`**. This project is currently locked by an unapplied plan from pull #%d. To continue, delete the lock from #%d or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.", + "This project is currently locked by an unapplied plan from pull #%d. To continue, delete the lock from #%d or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.", lockAttempt.CurrLock.Pull.Num, lockAttempt.CurrLock.Pull.Num) return &TryLockResponse{ diff --git a/server/events/project_locker_test.go b/server/events/project_locker_test.go index 0a6dd86e27..fdb6fb11d9 100644 --- a/server/events/project_locker_test.go +++ b/server/events/project_locker_test.go @@ -52,7 +52,7 @@ func TestDefaultProjectLocker_TryLockWhenLocked(t *testing.T) { Ok(t, err) Equals(t, &events.TryLockResponse{ LockAcquired: false, - LockFailureReason: "**Unable to run `plan`**. This project is currently locked by an unapplied plan from pull #2. To continue, delete the lock from #2 or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.", + LockFailureReason: "This project is currently locked by an unapplied plan from pull #2. To continue, delete the lock from #2 or apply that plan and merge the pull request.\n\nOnce the lock is released, comment `atlantis plan` here to re-plan.", }, res) } diff --git a/testing/assertions.go b/testing/assertions.go index 8d58ce0c54..918e342856 100644 --- a/testing/assertions.go +++ b/testing/assertions.go @@ -14,9 +14,6 @@ package testing import ( - "fmt" - "path/filepath" - "runtime" "strings" "testing" @@ -27,9 +24,9 @@ import ( // Assert fails the test if the condition is false. // Taken from https://github.com/benbjohnson/testing. func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) { + tb.Helper() if !condition { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) + errLog(tb, msg, v...) tb.FailNow() } } @@ -37,9 +34,9 @@ func Assert(tb testing.TB, condition bool, msg string, v ...interface{}) { // Ok fails the test if an err is not nil. // Taken from https://github.com/benbjohnson/testing. func Ok(tb testing.TB, err error) { + tb.Helper() if err != nil { - _, file, line, _ := runtime.Caller(1) - fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) + errLog(tb, "unexpected error: %s", err.Error()) tb.FailNow() } } @@ -49,8 +46,8 @@ func Ok(tb testing.TB, err error) { func Equals(tb testing.TB, exp, act interface{}) { tb.Helper() if diff := deep.Equal(exp, act); diff != nil { - _, file, line, _ := runtime.Caller(1) - 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)) + errLog(tb, "%s\n\nexp: %s******\ngot: %s", diff, spew.Sdump(exp), spew.Sdump(act)) + tb.FailNow() } } @@ -58,10 +55,12 @@ func Equals(tb testing.TB, exp, act interface{}) { func ErrEquals(tb testing.TB, exp string, act error) { tb.Helper() if act == nil { - tb.Fatalf("exp err %q but err was nil\n", exp) + errLog(tb, "exp err %q but err was nil\n", exp) + tb.FailNow() } if act.Error() != exp { - tb.Fatalf("exp err: %q but got: %q\n", exp, act.Error()) + errLog(tb, "exp err: %q but got: %q\n", exp, act.Error()) + tb.FailNow() } } @@ -70,21 +69,28 @@ func ErrEquals(tb testing.TB, exp string, act error) { func ErrContains(tb testing.TB, substr string, act error) { tb.Helper() if act == nil { - tb.Fatalf("exp err to contain %q but err was nil", substr) + errLog(tb, "exp err to contain %q but err was nil", substr) + tb.FailNow() } if !strings.Contains(act.Error(), substr) { - tb.Fatalf("exp err %q to contain %q", act.Error(), substr) + errLog(tb, "exp err %q to contain %q", act.Error(), substr) + tb.FailNow() } } // Contains fails the test if the slice doesn't contain the expected element func Contains(tb testing.TB, exp interface{}, slice []string) { + tb.Helper() for _, v := range slice { if v == exp { return } } - _, file, line, _ := runtime.Caller(1) - 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) + errLog(tb, "exp: %#v\n\n\twas not in: %#v", exp, slice) tb.FailNow() } + +func errLog(tb testing.TB, fmt string, args ...interface{}) { + tb.Helper() + tb.Logf("\033[31m"+fmt+"\033[39m", args...) +}