(t *testing.T)
| 259 | } |
| 260 | |
| 261 | func TestNewTemplateInspectorFromString(t *testing.T) { |
| 262 | testCases := []struct { |
| 263 | name string |
| 264 | template string |
| 265 | expected string |
| 266 | }{ |
| 267 | { |
| 268 | name: "empty template outputs json by default", |
| 269 | template: "", |
| 270 | expected: `[ |
| 271 | { |
| 272 | "Name": "test" |
| 273 | } |
| 274 | ] |
| 275 | `, |
| 276 | }, |
| 277 | { |
| 278 | name: "json specific value outputs json", |
| 279 | template: "json", |
| 280 | expected: `[{"Name":"test"}] |
| 281 | `, |
| 282 | }, |
| 283 | { |
| 284 | name: "template is applied", |
| 285 | template: "{{.Name}}", |
| 286 | expected: "test\n", |
| 287 | }, |
| 288 | } |
| 289 | value := struct { |
| 290 | Name string |
| 291 | }{ |
| 292 | "test", |
| 293 | } |
| 294 | for _, tc := range testCases { |
| 295 | t.Run(tc.name, func(t *testing.T) { |
| 296 | b := new(bytes.Buffer) |
| 297 | i, err := NewTemplateInspectorFromString(b, tc.template) |
| 298 | assert.NilError(t, err) |
| 299 | |
| 300 | err = i.Inspect(value, nil) |
| 301 | assert.NilError(t, err) |
| 302 | |
| 303 | err = i.Flush() |
| 304 | assert.NilError(t, err) |
| 305 | |
| 306 | assert.Equal(t, b.String(), tc.expected) |
| 307 | }) |
| 308 | } |
| 309 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…