(t *testing.T)
| 182 | } |
| 183 | |
| 184 | func 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 |
| 209 | alice key11, key12 |
| 210 | bob key21 |
| 211 | eve foobarbazqux, key31, key32 |
| 212 | `, |
| 213 | }, |
| 214 | // No truncation |
| 215 | { |
| 216 | formatter.Context{ |
| 217 | Format: defaultSignerInfoTableFormat, |
| 218 | }, |
| 219 | `SIGNER KEYS |
| 220 | alice key11, key12 |
| 221 | bob key21 |
| 222 | eve 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…