(t *testing.T)
| 713 | } |
| 714 | |
| 715 | func TestLogMetadata(t *testing.T) { |
| 716 | tests := []struct { |
| 717 | name string |
| 718 | metadata metadata.Metadata |
| 719 | expected string // Expected log message pattern |
| 720 | }{ |
| 721 | { |
| 722 | name: "git metadata logs SHA", |
| 723 | metadata: &gitMetadata.GitMetadata{ |
| 724 | LatestCommit: "abc123456789", |
| 725 | }, |
| 726 | expected: "SHA: abc123456789", |
| 727 | }, |
| 728 | { |
| 729 | name: "oci metadata logs digest", |
| 730 | metadata: &ociMetadata.OCIMetadata{ |
| 731 | Digest: "sha256:abcdef123456", |
| 732 | }, |
| 733 | expected: "Image digest: sha256:abcdef123456", |
| 734 | }, |
| 735 | { |
| 736 | name: "file metadata logs path", |
| 737 | metadata: &fileMetadata.FSMetadata{ |
| 738 | Path: "/tmp/test/path", |
| 739 | }, |
| 740 | expected: "Path: /tmp/test/path", |
| 741 | }, |
| 742 | { |
| 743 | name: "nil metadata logs nothing", |
| 744 | metadata: nil, |
| 745 | expected: "", // No log expected |
| 746 | }, |
| 747 | } |
| 748 | |
| 749 | for _, tt := range tests { |
| 750 | t.Run(tt.name, func(t *testing.T) { |
| 751 | // Since logMetadata uses log.Debugf which is hard to capture, |
| 752 | // we test the function's behavior by ensuring it doesn't panic |
| 753 | // and handles different metadata types correctly |
| 754 | |
| 755 | // This should not panic regardless of metadata type |
| 756 | assert.NotPanics(t, func() { |
| 757 | logMetadata(tt.metadata) |
| 758 | }, "logMetadata should not panic with any metadata type") |
| 759 | |
| 760 | // Test type assertions work correctly |
| 761 | if tt.metadata != nil { |
| 762 | switch v := tt.metadata.(type) { |
| 763 | case *gitMetadata.GitMetadata: |
| 764 | assert.NotEmpty(t, v.LatestCommit, "GitMetadata should have LatestCommit") |
| 765 | case *ociMetadata.OCIMetadata: |
| 766 | assert.NotEmpty(t, v.Digest, "OCIMetadata should have Digest") |
| 767 | case *fileMetadata.FSMetadata: |
| 768 | assert.NotEmpty(t, v.Path, "FSMetadata should have Path") |
| 769 | } |
| 770 | } |
| 771 | }) |
| 772 | } |
nothing calls this directly
no test coverage detected