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

Function TestNewTemplateInspectorFromString

cli/command/inspect/inspector_test.go:261–309  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

259}
260
261func TestNewTemplateInspectorFromString(t *testing.T) {
262 testCases := []struct {
263 name string
264 template string
265 expected string
266 }{
267 {
268 name: "empty template outputs json by default",
269 template: "",
270 expected: `[
271 {
272 "Name": "test"
273 }
274]
275`,
276 },
277 {
278 name: "json specific value outputs json",
279 template: "json",
280 expected: `[{"Name":"test"}]
281`,
282 },
283 {
284 name: "template is applied",
285 template: "{{.Name}}",
286 expected: "test\n",
287 },
288 }
289 value := struct {
290 Name string
291 }{
292 "test",
293 }
294 for _, tc := range testCases {
295 t.Run(tc.name, func(t *testing.T) {
296 b := new(bytes.Buffer)
297 i, err := NewTemplateInspectorFromString(b, tc.template)
298 assert.NilError(t, err)
299
300 err = i.Inspect(value, nil)
301 assert.NilError(t, err)
302
303 err = i.Flush()
304 assert.NilError(t, err)
305
306 assert.Equal(t, b.String(), tc.expected)
307 })
308 }
309}

Callers

nothing calls this directly

Calls 4

InspectMethod · 0.65
FlushMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…