| 349 | } |
| 350 | |
| 351 | func TestLockMetadataToJSON(t *testing.T) { |
| 352 | tests := []struct { |
| 353 | name string |
| 354 | metadata *LockMetadata |
| 355 | contains []string |
| 356 | notContains []string |
| 357 | }{ |
| 358 | { |
| 359 | name: "basic metadata", |
| 360 | metadata: &LockMetadata{ |
| 361 | SchemaVersion: LockSchemaV1, |
| 362 | FrontmatterHash: "test123", |
| 363 | }, |
| 364 | contains: []string{ |
| 365 | `"schema_version":"v1"`, |
| 366 | `"frontmatter_hash":"test123"`, |
| 367 | }, |
| 368 | notContains: []string{`"strict"`}, |
| 369 | }, |
| 370 | { |
| 371 | name: "metadata with empty hash", |
| 372 | metadata: &LockMetadata{ |
| 373 | SchemaVersion: LockSchemaV1, |
| 374 | FrontmatterHash: "", |
| 375 | }, |
| 376 | contains: []string{ |
| 377 | `"schema_version":"v1"`, |
| 378 | }, |
| 379 | }, |
| 380 | { |
| 381 | name: "metadata with compiler version", |
| 382 | metadata: &LockMetadata{ |
| 383 | SchemaVersion: LockSchemaV1, |
| 384 | FrontmatterHash: "test123", |
| 385 | CompilerVersion: "v0.1.2", |
| 386 | }, |
| 387 | contains: []string{ |
| 388 | `"schema_version":"v1"`, |
| 389 | `"frontmatter_hash":"test123"`, |
| 390 | `"compiler_version":"v0.1.2"`, |
| 391 | }, |
| 392 | }, |
| 393 | { |
| 394 | name: "v2 metadata with strict=true", |
| 395 | metadata: &LockMetadata{ |
| 396 | SchemaVersion: LockSchemaV2, |
| 397 | FrontmatterHash: "test123", |
| 398 | Strict: true, |
| 399 | }, |
| 400 | contains: []string{ |
| 401 | `"schema_version":"v2"`, |
| 402 | `"frontmatter_hash":"test123"`, |
| 403 | `"strict":true`, |
| 404 | }, |
| 405 | }, |
| 406 | { |
| 407 | name: "v2 metadata with strict=false omits strict field", |
| 408 | metadata: &LockMetadata{ |