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

Function TestSignerInfoContextWrite

cmd/docker-trust/trust/formatter_test.go:184–244  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestSignerInfoContextWrite(t *testing.T) {
185 cases := []struct {
186 context formatter.Context
187 expected string
188 }{
189 // Errors
190 {
191 formatter.Context{
192 Format: "{{InvalidFunction}}",
193 },
194 `template parsing error: template: :1: function "InvalidFunction" not defined`,
195 },
196 {
197 formatter.Context{
198 Format: "{{nil}}",
199 },
200 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
201 },
202 // Table Format
203 {
204 formatter.Context{
205 Format: defaultSignerInfoTableFormat,
206 Trunc: true,
207 },
208 `SIGNER KEYS
209alice key11, key12
210bob key21
211eve foobarbazqux, key31, key32
212`,
213 },
214 // No truncation
215 {
216 formatter.Context{
217 Format: defaultSignerInfoTableFormat,
218 },
219 `SIGNER KEYS
220alice key11, key12
221bob key21
222eve foobarbazquxquux, key31, key32
223`,
224 },
225 }
226
227 signerInfo := []signerInfo{
228 {Name: "alice", Keys: []string{"key11", "key12"}},
229 {Name: "bob", Keys: []string{"key21"}},
230 {Name: "eve", Keys: []string{"key31", "key32", "foobarbazquxquux"}},
231 }
232 for _, tc := range cases {
233 t.Run(string(tc.context.Format), func(t *testing.T) {
234 var out bytes.Buffer
235 tc.context.Output = &out
236
237 if err := signerInfoWrite(tc.context, signerInfo); err != nil {
238 assert.Error(t, err, tc.expected)
239 } else {
240 assert.Equal(t, out.String(), tc.expected)
241 }

Callers

nothing calls this directly

Calls 3

signerInfoWriteFunction · 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…