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

Function TestFormatInfo

cli/command/system/info_test.go:442–483  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

440}
441
442func TestFormatInfo(t *testing.T) {
443 for _, tc := range []struct {
444 doc string
445 template string
446 expectedError string
447 expectedOut string
448 }{
449 {
450 doc: "basic",
451 template: "{{.ID}}",
452 expectedOut: sampleID + "\n",
453 },
454 {
455 doc: "syntax",
456 template: "{{}",
457 expectedError: `template parsing error: template: :1: unexpected "}" in command`,
458 },
459 {
460 doc: "syntax",
461 template: "{{.badString}}",
462 expectedError: `template: :1:2: executing "" at <.badString>: can't evaluate field badString in type system.dockerInfo`,
463 },
464 } {
465 t.Run(tc.doc, func(t *testing.T) {
466 cli := test.NewFakeCli(&fakeClient{})
467 info := dockerInfo{
468 Info: &sampleInfoNoSwarm,
469 ClientInfo: &clientInfo{Debug: true},
470 }
471 err := formatInfo(cli.Out(), info, tc.template)
472 switch {
473 case tc.expectedOut != "":
474 assert.NilError(t, err)
475 assert.Equal(t, cli.OutBuffer().String(), tc.expectedOut)
476 case tc.expectedError != "":
477 assert.Error(t, err, tc.expectedError)
478 default:
479 t.Fatal("test expected to neither pass nor fail")
480 }
481 })
482 }
483}
484
485func TestNeedsServerInfo(t *testing.T) {
486 tests := []struct {

Callers

nothing calls this directly

Calls 5

OutMethod · 0.95
OutBufferMethod · 0.95
formatInfoFunction · 0.85
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…