(t *testing.T)
| 261 | } |
| 262 | |
| 263 | func TestLoadMetadataLegacy(t *testing.T) { |
| 264 | testCases := map[string]struct { |
| 265 | yaml string |
| 266 | expectError bool |
| 267 | errorContains string |
| 268 | expectedName string |
| 269 | logNote string |
| 270 | }{ |
| 271 | "capital name field": { |
| 272 | yaml: `Name: my-plugin |
| 273 | version: 1.0.0 |
| 274 | usage: test plugin |
| 275 | description: test description |
| 276 | command: echo test`, |
| 277 | expectError: true, |
| 278 | errorContains: `invalid plugin name "": must contain only a-z, A-Z, 0-9, _ and -`, |
| 279 | // Legacy plugins: No strict unmarshalling (backwards compatibility) |
| 280 | // YAML decoder silently ignores "Name:", then validation catches empty name |
| 281 | logNote: "NOTE: V1 plugins use strict unmarshalling and would get: yaml: field Name not found", |
| 282 | }, |
| 283 | "correct name field": { |
| 284 | yaml: `name: my-plugin |
| 285 | version: 1.0.0 |
| 286 | usage: test plugin |
| 287 | description: test description |
| 288 | command: echo test`, |
| 289 | expectError: false, |
| 290 | expectedName: "my-plugin", |
| 291 | }, |
| 292 | } |
| 293 | |
| 294 | for name, tc := range testCases { |
| 295 | t.Run(name, func(t *testing.T) { |
| 296 | m, err := loadMetadataLegacy([]byte(tc.yaml)) |
| 297 | |
| 298 | if tc.expectError { |
| 299 | require.Error(t, err) |
| 300 | assert.Contains(t, err.Error(), tc.errorContains) |
| 301 | t.Logf("Legacy error (validation catches empty name): %v", err) |
| 302 | if tc.logNote != "" { |
| 303 | t.Log(tc.logNote) |
| 304 | } |
| 305 | } else { |
| 306 | require.NoError(t, err) |
| 307 | assert.Equal(t, tc.expectedName, m.Name) |
| 308 | } |
| 309 | }) |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | func TestLoadMetadataV1(t *testing.T) { |
| 314 | testCases := map[string]struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…