(t *testing.T)
| 311 | } |
| 312 | |
| 313 | func TestLoadMetadataV1(t *testing.T) { |
| 314 | testCases := map[string]struct { |
| 315 | yaml string |
| 316 | expectError bool |
| 317 | errorContains string |
| 318 | expectedName string |
| 319 | }{ |
| 320 | "capital name field": { |
| 321 | yaml: `apiVersion: v1 |
| 322 | Name: my-plugin |
| 323 | type: cli/v1 |
| 324 | runtime: subprocess |
| 325 | `, |
| 326 | expectError: true, |
| 327 | errorContains: "field Name not found in type plugin.MetadataV1", |
| 328 | }, |
| 329 | "correct name field": { |
| 330 | yaml: `apiVersion: v1 |
| 331 | name: my-plugin |
| 332 | version: 1.0.0 |
| 333 | type: cli/v1 |
| 334 | runtime: subprocess |
| 335 | `, |
| 336 | expectError: false, |
| 337 | expectedName: "my-plugin", |
| 338 | }, |
| 339 | } |
| 340 | |
| 341 | for name, tc := range testCases { |
| 342 | t.Run(name, func(t *testing.T) { |
| 343 | m, err := loadMetadataV1([]byte(tc.yaml)) |
| 344 | |
| 345 | if tc.expectError { |
| 346 | require.Error(t, err) |
| 347 | assert.Contains(t, err.Error(), tc.errorContains) |
| 348 | t.Logf("V1 error (strict unmarshalling): %v", err) |
| 349 | } else { |
| 350 | require.NoError(t, err) |
| 351 | assert.Equal(t, tc.expectedName, m.Name) |
| 352 | } |
| 353 | }) |
| 354 | } |
| 355 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…