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

Function TestSecretInspectWithFormat

cli/command/secret/inspect_test.go:114–156  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestSecretInspectWithFormat(t *testing.T) {
115 secretInspectFunc := func(_ context.Context, name string, _ client.SecretInspectOptions) (client.SecretInspectResult, error) {
116 return client.SecretInspectResult{
117 Secret: *builders.Secret(
118 builders.SecretName("foo"),
119 builders.SecretLabels(map[string]string{
120 "label1": "label-foo",
121 }),
122 ),
123 }, nil
124 }
125 testCases := []struct {
126 name string
127 format string
128 args []string
129 secretInspectFunc func(_ context.Context, name string, _ client.SecretInspectOptions) (client.SecretInspectResult, error)
130 }{
131 {
132 name: "simple-template",
133 format: "{{.Spec.Name}}",
134 args: []string{"foo"},
135 secretInspectFunc: secretInspectFunc,
136 },
137 {
138 name: "json-template",
139 format: "{{json .Spec.Labels}}",
140 args: []string{"foo"},
141 secretInspectFunc: secretInspectFunc,
142 },
143 }
144 for _, tc := range testCases {
145 t.Run(tc.name, func(t *testing.T) {
146 cli := test.NewFakeCli(&fakeClient{
147 secretInspectFunc: tc.secretInspectFunc,
148 })
149 cmd := newSecretInspectCommand(cli)
150 cmd.SetArgs(tc.args)
151 assert.Check(t, cmd.Flags().Set("format", tc.format))
152 assert.NilError(t, cmd.Execute())
153 golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
154 })
155 }
156}
157
158func TestSecretInspectPretty(t *testing.T) {
159 testCases := []struct {

Callers

nothing calls this directly

Calls 5

OutBufferMethod · 0.95
newSecretInspectCommandFunction · 0.85
SetArgsMethod · 0.80
StringMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…