Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make project locked message look better. #336

Merged
merged 2 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion server/events/pending_plan_finder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestPendingPlanFinder_FindPlanCheckedIn(t *testing.T) {
runCmd(t, repoDir, "git", "add", ".")
runCmd(t, repoDir, "git", "config", "--local", "user.email", "[email protected]")
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)
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion server/events/project_locker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion server/events/project_locker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
36 changes: 21 additions & 15 deletions testing/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
package testing

import (
"fmt"
"path/filepath"
"runtime"
"strings"
"testing"

Expand All @@ -27,19 +24,19 @@ 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()
}
}

// 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()
}
}
Expand All @@ -49,19 +46,21 @@ 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()
}
}

// ErrEquals fails the test if act is nil or act.Error() != exp
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()
}
}

Expand All @@ -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...)
}