(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestExtractMetadataFromLockFile(t *testing.T) { |
| 13 | tests := []struct { |
| 14 | name string |
| 15 | content string |
| 16 | expectMetadata *LockMetadata |
| 17 | expectLegacy bool |
| 18 | expectError bool |
| 19 | }{ |
| 20 | { |
| 21 | name: "valid v1 metadata", |
| 22 | content: `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"abc123"} |
| 23 | name: test |
| 24 | `, |
| 25 | expectMetadata: &LockMetadata{ |
| 26 | SchemaVersion: LockSchemaV1, |
| 27 | FrontmatterHash: "abc123", |
| 28 | }, |
| 29 | expectLegacy: false, |
| 30 | expectError: false, |
| 31 | }, |
| 32 | { |
| 33 | name: "valid v1 metadata with spaces", |
| 34 | content: `# gh-aw-metadata: {"schema_version":"v1","frontmatter_hash":"def456"} |
| 35 | name: test |
| 36 | `, |
| 37 | expectMetadata: &LockMetadata{ |
| 38 | SchemaVersion: LockSchemaV1, |
| 39 | FrontmatterHash: "def456", |
| 40 | }, |
| 41 | expectLegacy: false, |
| 42 | expectError: false, |
| 43 | }, |
| 44 | { |
| 45 | name: "legacy format with frontmatter-hash only", |
| 46 | content: `# frontmatter-hash: 1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef |
| 47 | name: test |
| 48 | `, |
| 49 | expectMetadata: &LockMetadata{ |
| 50 | FrontmatterHash: "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef", |
| 51 | }, |
| 52 | expectLegacy: true, |
| 53 | expectError: false, |
| 54 | }, |
| 55 | { |
| 56 | name: "no metadata", |
| 57 | content: `name: test |
| 58 | on: push |
| 59 | `, |
| 60 | expectMetadata: nil, |
| 61 | expectLegacy: false, |
| 62 | expectError: false, |
| 63 | }, |
| 64 | { |
| 65 | name: "malformed JSON metadata", |
| 66 | content: `# gh-aw-metadata: {invalid json} |
| 67 | name: test |
| 68 | `, |
| 69 | expectMetadata: nil, |
nothing calls this directly
no test coverage detected