You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
834 B

  1. package matchers
  2. import (
  3. "fmt"
  4. "github.com/onsi/gomega/format"
  5. )
  6. type SucceedMatcher struct {
  7. }
  8. func (matcher *SucceedMatcher) Match(actual interface{}) (success bool, err error) {
  9. // is purely nil?
  10. if actual == nil {
  11. return true, nil
  12. }
  13. // must be an 'error' type
  14. if !isError(actual) {
  15. return false, fmt.Errorf("Expected an error-type. Got:\n%s", format.Object(actual, 1))
  16. }
  17. // must be nil (or a pointer to a nil)
  18. return isNil(actual), nil
  19. }
  20. func (matcher *SucceedMatcher) FailureMessage(actual interface{}) (message string) {
  21. return fmt.Sprintf("Expected success, but got an error:\n%s\n%s", format.Object(actual, 1), format.IndentString(actual.(error).Error(), 1))
  22. }
  23. func (matcher *SucceedMatcher) NegatedFailureMessage(actual interface{}) (message string) {
  24. return "Expected failure, but got no error."
  25. }