MCPcopy
hub / github.com/docker/compose / TestPrint

Function TestPrint

cmd/formatter/formatter_test.go:35–74  ·  view source on GitHub ↗

Print prints formatted lists in different formats

(t *testing.T)

Source from the content-addressed store, hash-verified

33
34// Print prints formatted lists in different formats
35func TestPrint(t *testing.T) {
36 testList := []testStruct{
37 {
38 Name: "myName1",
39 Status: "myStatus1",
40 },
41 {
42 Name: "myName2",
43 Status: "myStatus2",
44 },
45 }
46
47 b := &bytes.Buffer{}
48 assert.NilError(t, Print(testList, TABLE, b, func(w io.Writer) {
49 for _, t := range testList {
50 _, _ = fmt.Fprintf(w, "%s\t%s\n", t.Name, t.Status)
51 }
52 }, "NAME", "STATUS"))
53 assert.Equal(t, b.String(), "NAME STATUS\nmyName1 myStatus1\nmyName2 myStatus2\n")
54
55 b.Reset()
56 assert.NilError(t, Print(testList, JSON, b, func(w io.Writer) {
57 for _, t := range testList {
58 _, _ = fmt.Fprintf(w, "%s\t%s\n", t.Name, t.Status)
59 }
60 }, "NAME", "STATUS"))
61 assert.Equal(t, b.String(), `[{"Name":"myName1","Status":"myStatus1"},{"Name":"myName2","Status":"myStatus2"}]
62`)
63
64 b.Reset()
65 assert.NilError(t, Print(testList, TemplateLegacyJSON, b, func(w io.Writer) {
66 for _, t := range testList {
67 _, _ = fmt.Fprintf(w, "%s\t%s\n", t.Name, t.Status)
68 }
69 }, "NAME", "STATUS"))
70 json := b.String()
71 assert.Equal(t, json, `{"Name":"myName1","Status":"myStatus1"}
72{"Name":"myName2","Status":"myStatus2"}
73`)
74}
75
76func TestColorsGoroutinesLeak(t *testing.T) {
77 goleak.VerifyNone(t)

Callers

nothing calls this directly

Calls 2

PrintFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected