MCPcopy Index your code
hub / github.com/docker/cli / TestSearchContextWrite

Function TestSearchContextWrite

cli/command/registry/formatter_search_test.go:128–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

126}
127
128func TestSearchContextWrite(t *testing.T) {
129 cases := []struct {
130 doc string
131 format formatter.Format
132 expected string
133 expectedErr string
134 }{
135 {
136 doc: "Errors",
137 format: "{{InvalidFunction}}",
138 expectedErr: `template parsing error: template: :1: function "InvalidFunction" not defined`,
139 },
140 {
141 doc: "Nil format",
142 format: "{{nil}}",
143 expectedErr: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
144 },
145 {
146 doc: "JSON format",
147 format: "{{json .}}",
148 expected: `{"Description":"Official build","IsOfficial":"true","Name":"result1","StarCount":"5000"}
149{"Description":"Not official","IsOfficial":"false","Name":"result2","StarCount":"5"}
150`,
151 },
152 {
153 doc: "JSON format, single field",
154 format: "{{json .Name}}",
155 expected: `"result1"
156"result2"
157`,
158 },
159 {
160 doc: "Table format",
161 format: newFormat("table"),
162 expected: string(golden.Get(t, "search-context-write-table.golden")),
163 },
164 {
165 doc: "Table format, single column",
166 format: newFormat("table {{.Name}}"),
167 expected: `NAME
168result1
169result2
170`,
171 },
172 {
173 doc: "Custom format, single field",
174 format: newFormat("{{.Name}}"),
175 expected: `result1
176result2
177`,
178 },
179 {
180 doc: "Custom Format, two columns",
181 format: newFormat("{{.Name}} {{.StarCount}}"),
182 expected: `result1 5000
183result2 5
184`,
185 },

Callers

nothing calls this directly

Calls 5

newFormatFunction · 0.70
formatWriteFunction · 0.70
GetMethod · 0.65
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…