(t *testing.T)
| 440 | } |
| 441 | |
| 442 | func 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 | |
| 485 | func TestNeedsServerInfo(t *testing.T) { |
| 486 | tests := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…