File: have_cap_matcher.go

package info (click to toggle)
golang-gomega 1.0%2Bgit20160910.d59fa0a-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 728 kB
  • ctags: 691
  • sloc: makefile: 12
file content (28 lines) | stat: -rw-r--r-- 777 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package matchers

import (
	"fmt"

	"github.com/onsi/gomega/format"
)

type HaveCapMatcher struct {
	Count int
}

func (matcher *HaveCapMatcher) Match(actual interface{}) (success bool, err error) {
	length, ok := capOf(actual)
	if !ok {
		return false, fmt.Errorf("HaveCap matcher expects a array/channel/slice.  Got:\n%s", format.Object(actual, 1))
	}

	return length == matcher.Count, nil
}

func (matcher *HaveCapMatcher) FailureMessage(actual interface{}) (message string) {
	return fmt.Sprintf("Expected\n%s\nto have capacity %d", format.Object(actual, 1), matcher.Count)
}

func (matcher *HaveCapMatcher) NegatedFailureMessage(actual interface{}) (message string) {
	return fmt.Sprintf("Expected\n%s\nnot to have capacity %d", format.Object(actual, 1), matcher.Count)
}