-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (55 loc) · 1.73 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"bytes"
"strings"
"code.cloudfoundry.org/cli/cf/terminal"
"code.cloudfoundry.org/cli/util/testhelpers/io"
"github.com/wfernandes/CLITableMatcher"
)
func main() {
actualTable := terminal.NewTable([]string{"Name", "Type"})
actualTable.Add("name1", "type1")
actualTable.Add("name2", "type2")
// copy the object
expectedTable := &terminal.Table{}
*expectedTable = *actualTable
var b []byte
actualOutput := bytes.NewBuffer(b)
actualTable.PrintTo(actualOutput)
actual := actualOutput.String()
capturedOutput := io.CaptureOutput(func() {
fmt.Println(actualOutput)
})
println("len of captured output:", len(capturedOutput))
println("len of actual output", len(strings.Split(actualOutput.String(), "\n")))
formattedCapturedOutput := strings.Join(capturedOutput[:len(capturedOutput)-1], "\n")
fmt.Printf("Formatted Captured:\n%s", formattedCapturedOutput)
fmt.Printf("Actual:\n%s", actual)
success, err := cli_table_matcher.ContainCLITable(expectedTable).Match(formattedCapturedOutput)
if err != nil {
panic(err)
}
if success {
fmt.Println("Match was successful")
} else {
fmt.Println("Match was unsuccessful")
}
}
func demonstratePrintToWeirdness(t *terminal.Table) {
var b1 []byte
output1 := bytes.NewBuffer(b1)
var b2 []byte
output2 := bytes.NewBuffer(b2)
t.PrintTo(output1)
// For some reason once t.PrintTo is called once for against the object
// it is pointing to, it is unable to print again. That is, output2 is
// empty.
// A comment inside the PrintTo function mentions that the rows get
// cleared out so it cannot be printed again.
t.PrintTo(output2)
actual1 := output1.String()
actual2 := output2.String()
fmt.Printf("Actual1:\n%s", actual1)
fmt.Printf("Actual2:\n%s", actual2)
}