diff --git a/cmd/pm/tasks/createIssue.go b/cmd/pm/tasks/createIssue.go index 636f2ba..a600c47 100644 --- a/cmd/pm/tasks/createIssue.go +++ b/cmd/pm/tasks/createIssue.go @@ -74,28 +74,11 @@ func (t *CreateIssueTask) Validate(ctx context.Context) ValidationFeedback { issue := issues[0] - expect.Assert(len(issues) < 2, "Multiple issues were created instead of one. Delete the extra issues and try again.") + expect.Assert(len(issues) < 2, "Multiple issues were created instead of one") - if issue.Title == "" { - expect.Fail("Issue title should not be empty, but it is empty") - } else { - expect.Assert(issue.Title == "My first Issue", - fmt.Sprintf("Issue title does not match the expected value 'My first Issue', but was '%s'", issue.Title)) - } - - if issue.Description == "" { - expect.Fail("Issue description should not be empty, but it is empty") - } else { - expect.Assert(issue.Description == "I need to do some coding", - fmt.Sprintf("Issue description does not match the expected value 'I need to do some coding', but was '%s'", issue.Description)) - } - - if issue.Assignee == "" { - expect.Fail("Issue should be assigned to 'Me', but it is not assigned to anyone") - } else { - expect.Assert(issue.Assignee == "Me", - fmt.Sprintf("Issue should be assigned to 'Me', but was assigned to '%s'", issue.Assignee)) - } + expect.NotEmptyAndEqual(issue.Title, "My first Issue", "Issue title") + expect.NotEmptyAndEqual(issue.Description, "I need to do some coding", "Issue description") + expect.NotEmptyAndEqual(issue.Assignee, "Me", "Issue assignee") expect.Assert(issue.Status == models.StatusInProgress, fmt.Sprintf("Issue status should be 'In Progress', but was '%s'", issue.Status)) diff --git a/internal/utils/check/expect.go b/internal/utils/check/expect.go index 670fcdb..2b9b2f3 100644 --- a/internal/utils/check/expect.go +++ b/internal/utils/check/expect.go @@ -43,11 +43,6 @@ func (e *Expector) CompleteWithMessage(message string) ValidationFeedback { return e.ValidationFeedback } -func (e *Expector) Fail(message string) ValidationFeedback { - e.Checks = append(e.Checks, NewCheck(message, false)) - return e.ValidationFeedback -} - func (e *Expector) Errors() []error { var errors []error for _, check := range e.Checks { @@ -58,6 +53,25 @@ func (e *Expector) Errors() []error { return errors } +func (e *Expector) Pass(message string) *Expector { + e.Checks = append(e.Checks, NewCheck(message, true)) + return e +} + +func (e *Expector) Fail(message string) *Expector { + e.Checks = append(e.Checks, NewCheck(message, false)) + return e +} + +func (e *Expector) NotEmptyAndEqual(val, expected string, message string) *Expector { + if val == "" { + return e.Fail(fmt.Sprintf("%s is empty", message)) + } else if val != expected { + return e.Fail(fmt.Sprintf(`%s expected "%v", got "%v"`, message, expected, val)) + } + return e.Pass(message + " is correct") +} + func (e *Expector) Assert(condition bool, message string) *Expector { check := NewCheck(message, condition) e.Checks = append(e.Checks, check)