-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatcher.go
51 lines (40 loc) · 1.1 KB
/
matcher.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
45
46
47
48
49
50
51
package cli_table_matcher
import (
"bytes"
"strings"
"fmt"
"code.cloudfoundry.org/cli/cf/terminal"
"github.com/onsi/gomega/types"
)
type tableMatcher struct {
expected *terminal.Table
expectedStr string
}
func ContainCLITable(expected *terminal.Table) types.GomegaMatcher {
return &tableMatcher{
expected: expected,
}
}
func (m *tableMatcher) Match(actual interface{}) (bool, error) {
a, ok := actual.(string)
if !ok {
return false, fmt.Errorf("CLITable matcher expects a string")
}
var b []byte
expectedBytes := bytes.NewBuffer(b)
err := m.expected.PrintTo(expectedBytes)
if err != nil {
return false, fmt.Errorf("unable to process expected")
}
m.expectedStr = strings.TrimSpace(expectedBytes.String())
if strings.Contains(a, m.expectedStr) {
return true, nil
}
return false, nil
}
func (m *tableMatcher) FailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected \n%s to match \n%s", actual, m.expectedStr)
}
func (m *tableMatcher) NegatedFailureMessage(actual interface{}) string {
return fmt.Sprintf("Expected \n%s to not match \n%s", actual, m.expectedStr)
}