forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.go
44 lines (35 loc) · 1.12 KB
/
matchers.go
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package fakes
import (
"fmt"
"github.com/onsi/gomega/types"
)
func BeASubstageOf(expected interface{}) types.GomegaMatcher {
return &beASubstageOfMatcher{
parent: expected,
}
}
type beASubstageOfMatcher struct {
parent interface{}
}
func (matcher *beASubstageOfMatcher) Match(child interface{}) (success bool, err error) {
substage, ok := child.(*FakeStage)
if !ok {
return false, fmt.Errorf("BeASubstageOf matcher expects an *fakeui.FakeStage")
}
parentStage, ok := matcher.parent.(*FakeStage)
if !ok {
return false, fmt.Errorf("BeASubstageOf matcher expects an *fakeui.FakeStage for expected value")
}
for _, currentSubstage := range parentStage.SubStages {
if currentSubstage == substage {
return true, nil
}
}
return false, nil
}
func (matcher *beASubstageOfMatcher) FailureMessage(child interface{}) (message string) {
return fmt.Sprintf("Expected\n\t%#v\nto be a substage of\n\t%#v", child, matcher.parent)
}
func (matcher *beASubstageOfMatcher) NegatedFailureMessage(child interface{}) (message string) {
return fmt.Sprintf("Expected\n\t%#v\nto not be a substage of\n\t%#v", child, matcher.parent)
}