|
8 | 8 | "testing" |
9 | 9 |
|
10 | 10 | "github.com/jfrog/jfrog-cli-core/v2/utils/config" |
| 11 | + "github.com/jfrog/jfrog-cli-core/v2/utils/coreutils" |
11 | 12 | "github.com/stretchr/testify/assert" |
12 | 13 | ) |
13 | 14 |
|
@@ -212,3 +213,112 @@ func TestCreateEvidenceCustom_SigstoreBundleWithSubjectPath(t *testing.T) { |
212 | 213 | assert.Equal(t, bundlePath, custom.sigstoreBundlePath) |
213 | 214 | assert.Equal(t, "provided-repo/provided-artifact", custom.subjectRepoPath) |
214 | 215 | } |
| 216 | + |
| 217 | +func TestCreateEvidenceCustom_NewSubjectError_GitHubActions(t *testing.T) { |
| 218 | + _ = os.Setenv("GITHUB_ACTIONS", "true") |
| 219 | + defer func() { |
| 220 | + _ = os.Unsetenv("GITHUB_ACTIONS") |
| 221 | + }() |
| 222 | + |
| 223 | + serverDetails := &config.ServerDetails{ |
| 224 | + Url: "https://test.jfrog.io", |
| 225 | + User: "test-user", |
| 226 | + AccessToken: "test-token", |
| 227 | + } |
| 228 | + |
| 229 | + cmd := NewCreateEvidenceCustom( |
| 230 | + serverDetails, |
| 231 | + "predicate.json", |
| 232 | + "https://example.com/predicate/v1", |
| 233 | + "markdown.md", |
| 234 | + "key.pem", |
| 235 | + "key-alias", |
| 236 | + "test-repo/test-artifact", |
| 237 | + "abcd1234", |
| 238 | + "/path/to/sigstore-bundle.json", |
| 239 | + "test-provider", |
| 240 | + ) |
| 241 | + |
| 242 | + custom, ok := cmd.(*createEvidenceCustom) |
| 243 | + assert.True(t, ok, "cmd should be of type *createEvidenceCustom") |
| 244 | + |
| 245 | + testMessage := "Test error message" |
| 246 | + err := custom.newSubjectError(testMessage) |
| 247 | + |
| 248 | + assert.Error(t, err) |
| 249 | + cliErr, ok := err.(coreutils.CliError) |
| 250 | + assert.True(t, ok, "error should be of type CliError when running under GitHub Actions with sigstore bundle") |
| 251 | + assert.Equal(t, coreutils.ExitCodeFailNoOp, cliErr.ExitCode, "should return exit code 2 (ExitCodeFailNoOp)") |
| 252 | + assert.Equal(t, testMessage, cliErr.ErrorMsg, "error message should match") |
| 253 | +} |
| 254 | + |
| 255 | +func TestCreateEvidenceCustom_NewSubjectError_RegularExecution(t *testing.T) { |
| 256 | + _ = os.Unsetenv("GITHUB_ACTIONS") |
| 257 | + |
| 258 | + serverDetails := &config.ServerDetails{ |
| 259 | + Url: "https://test.jfrog.io", |
| 260 | + User: "test-user", |
| 261 | + AccessToken: "test-token", |
| 262 | + } |
| 263 | + |
| 264 | + cmd := NewCreateEvidenceCustom( |
| 265 | + serverDetails, |
| 266 | + "predicate.json", |
| 267 | + "https://example.com/predicate/v1", |
| 268 | + "markdown.md", |
| 269 | + "key.pem", |
| 270 | + "key-alias", |
| 271 | + "test-repo/test-artifact", |
| 272 | + "abcd1234", |
| 273 | + "/path/to/sigstore-bundle.json", |
| 274 | + "test-provider", |
| 275 | + ) |
| 276 | + |
| 277 | + custom, ok := cmd.(*createEvidenceCustom) |
| 278 | + assert.True(t, ok, "cmd should be of type *createEvidenceCustom") |
| 279 | + |
| 280 | + testMessage := "Test error message" |
| 281 | + err := custom.newSubjectError(testMessage) |
| 282 | + |
| 283 | + assert.Error(t, err) |
| 284 | + _, ok = err.(coreutils.CliError) |
| 285 | + assert.False(t, ok, "error should not be of type CliError when not running under GitHub Actions") |
| 286 | + assert.Contains(t, err.Error(), testMessage, "error message should contain the test message") |
| 287 | +} |
| 288 | + |
| 289 | +func TestCreateEvidenceCustom_NewSubjectError_GitHubActionsWithoutSigstoreBundle(t *testing.T) { |
| 290 | + _ = os.Setenv("GITHUB_ACTIONS", "true") |
| 291 | + defer func() { |
| 292 | + _ = os.Unsetenv("GITHUB_ACTIONS") |
| 293 | + }() |
| 294 | + |
| 295 | + serverDetails := &config.ServerDetails{ |
| 296 | + Url: "https://test.jfrog.io", |
| 297 | + User: "test-user", |
| 298 | + AccessToken: "test-token", |
| 299 | + } |
| 300 | + |
| 301 | + cmd := NewCreateEvidenceCustom( |
| 302 | + serverDetails, |
| 303 | + "predicate.json", |
| 304 | + "https://example.com/predicate/v1", |
| 305 | + "markdown.md", |
| 306 | + "key.pem", |
| 307 | + "key-alias", |
| 308 | + "test-repo/test-artifact", |
| 309 | + "abcd1234", |
| 310 | + "", |
| 311 | + "test-provider", |
| 312 | + ) |
| 313 | + |
| 314 | + custom, ok := cmd.(*createEvidenceCustom) |
| 315 | + assert.True(t, ok, "cmd should be of type *createEvidenceCustom") |
| 316 | + |
| 317 | + testMessage := "Test error message" |
| 318 | + err := custom.newSubjectError(testMessage) |
| 319 | + |
| 320 | + assert.Error(t, err) |
| 321 | + _, ok = err.(coreutils.CliError) |
| 322 | + assert.False(t, ok, "error should not be of type CliError when running under GitHub Actions but without sigstore bundle") |
| 323 | + assert.Contains(t, err.Error(), testMessage, "error message should contain the test message") |
| 324 | +} |
0 commit comments