MCPcopy Create free account
hub / github.com/docker/cli / TestContext

Function TestContext

cli/command/formatter/formatter_test.go:90–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

88}
89
90func TestContext(t *testing.T) {
91 testCases := []struct {
92 name string
93 format string
94 expected string
95 }{
96 {
97 name: "json format",
98 format: JSONFormatKey,
99 expected: `{"Name":"test"}
100`,
101 },
102 {
103 name: "table format",
104 format: `table {{.Name}}`,
105 expected: `NAME
106test
107`,
108 },
109 }
110 for _, tc := range testCases {
111 t.Run(tc.name, func(t *testing.T) {
112 buf := bytes.NewBuffer(nil)
113 ctx := Context{
114 Format: Format(tc.format),
115 Output: buf,
116 }
117 subContext := fakeSubContext{Name: "test"}
118 subFormat := func(f func(sub SubContext) error) error {
119 return f(subContext)
120 }
121 err := ctx.Write(&subContext, subFormat)
122 assert.NilError(t, err)
123 assert.Equal(t, buf.String(), tc.expected)
124 })
125 }
126}

Callers

nothing calls this directly

Calls 3

WriteMethod · 0.95
FormatTypeAlias · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…