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

Function TestSecretContextFormatWrite

cli/command/secret/formatter_test.go:14–76  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestSecretContextFormatWrite(t *testing.T) {
15 // Check default output format (verbose and non-verbose mode) for table headers
16 cases := []struct {
17 context formatter.Context
18 expected string
19 }{
20 // Errors
21 {
22 formatter.Context{Format: "{{InvalidFunction}}"},
23 `template parsing error: template: :1: function "InvalidFunction" not defined`,
24 },
25 {
26 formatter.Context{Format: "{{nil}}"},
27 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
28 },
29 // Table format
30 {
31 formatter.Context{Format: newFormat("table", false)},
32 `ID NAME DRIVER CREATED UPDATED
331 passwords Less than a second ago Less than a second ago
342 id_rsa Less than a second ago Less than a second ago
35`,
36 },
37 {
38 formatter.Context{Format: newFormat("table {{.Name}}", true)},
39 `NAME
40passwords
41id_rsa
42`,
43 },
44 {
45 formatter.Context{Format: newFormat("{{.ID}}-{{.Name}}", false)},
46 `1-passwords
472-id_rsa
48`,
49 },
50 }
51
52 secrets := []swarm.Secret{
53 {
54 ID: "1",
55 Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
56 Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "passwords"}},
57 },
58 {
59 ID: "2",
60 Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
61 Spec: swarm.SecretSpec{Annotations: swarm.Annotations{Name: "id_rsa"}},
62 },
63 }
64 for _, tc := range cases {
65 t.Run(string(tc.context.Format), func(t *testing.T) {
66 var out bytes.Buffer
67 tc.context.Output = &out
68
69 if err := formatWrite(tc.context, client.SecretListResult{Items: secrets}); err != nil {
70 assert.Error(t, err, tc.expected)
71 } else {

Callers

nothing calls this directly

Calls 4

newFormatFunction · 0.70
formatWriteFunction · 0.70
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…