have_cap_matcher.go 777 B

1234567891011121314151617181920212223242526272829
  1. package matchers
  2. import (
  3. "fmt"
  4. "github.com/onsi/gomega/format"
  5. )
  6. type HaveCapMatcher struct {
  7. Count int
  8. }
  9. func (matcher *HaveCapMatcher) Match(actual interface{}) (success bool, err error) {
  10. length, ok := capOf(actual)
  11. if !ok {
  12. return false, fmt.Errorf("HaveCap matcher expects a array/channel/slice. Got:\n%s", format.Object(actual, 1))
  13. }
  14. return length == matcher.Count, nil
  15. }
  16. func (matcher *HaveCapMatcher) FailureMessage(actual interface{}) (message string) {
  17. return fmt.Sprintf("Expected\n%s\nto have capacity %d", format.Object(actual, 1), matcher.Count)
  18. }
  19. func (matcher *HaveCapMatcher) NegatedFailureMessage(actual interface{}) (message string) {
  20. return fmt.Sprintf("Expected\n%s\nnot to have capacity %d", format.Object(actual, 1), matcher.Count)
  21. }