|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "fmt" |
| 6 | + "strings" |
5 | 7 | "testing" |
6 | 8 |
|
7 | 9 | "github.com/stretchr/testify/suite" |
@@ -114,6 +116,30 @@ func (suite *AttestArtifactCommandTestSuite) TestAttestArtifactCmd() { |
114 | 116 | runTestCmd(suite.T(), tests) |
115 | 117 | } |
116 | 118 |
|
| 119 | +// TestAttestArtifactPayload_RepoInfoOmittedWhenNil ensures that when GitRepoInfo |
| 120 | +// is not available (nil), the JSON payload does not include the repo_info field |
| 121 | +// (omitempty behavior). |
| 122 | +func TestAttestArtifactPayload_RepoInfoOmittedWhenNil(t *testing.T) { |
| 123 | + payload := AttestArtifactPayload{ |
| 124 | + Fingerprint: "abc123", |
| 125 | + Filename: "file1", |
| 126 | + GitCommit: "sha", |
| 127 | + BuildUrl: "https://build.example.com", |
| 128 | + CommitUrl: "https://commit.example.com", |
| 129 | + RepoUrl: "https://repo.example.com", |
| 130 | + Name: "cli", |
| 131 | + TrailName: "trail-1", |
| 132 | + GitRepoInfo: nil, // not available |
| 133 | + } |
| 134 | + data, err := json.Marshal(payload) |
| 135 | + if err != nil { |
| 136 | + t.Fatalf("marshal payload: %v", err) |
| 137 | + } |
| 138 | + if strings.Contains(string(data), "repo_info") { |
| 139 | + t.Errorf("payload must not include repo_info when GitRepoInfo is nil, got: %s", string(data)) |
| 140 | + } |
| 141 | +} |
| 142 | + |
117 | 143 | // In order for 'go test' to run this suite, we need to create |
118 | 144 | // a normal test function and pass our suite to suite.Run |
119 | 145 | func TestAttestArtifactCommandTestSuite(t *testing.T) { |
|
0 commit comments