diff --git a/pkg/cmd/attestation/inspect/inspect_test.go b/pkg/cmd/attestation/inspect/inspect_test.go index ba82d1b39..99b38876c 100644 --- a/pkg/cmd/attestation/inspect/inspect_test.go +++ b/pkg/cmd/attestation/inspect/inspect_test.go @@ -42,10 +42,11 @@ func TestNewInspectCmd(t *testing.T) { } testcases := []struct { - name string - cli string - wants Options - wantsErr bool + name string + cli string + wants Options + wantsErr bool + wantsExporter bool }{ { name: "Invalid digest-alg flag", @@ -90,6 +91,17 @@ func TestNewInspectCmd(t *testing.T) { }, wantsErr: true, }, + { + name: "Prints output in JSON format", + cli: fmt.Sprintf("%s --bundle %s --format json", artifactPath, bundlePath), + wants: Options{ + ArtifactPath: artifactPath, + BundlePath: bundlePath, + DigestAlgorithm: "sha256", + OCIClient: oci.MockClient{}, + }, + wantsExporter: true, + }, } for _, tc := range testcases { @@ -118,6 +130,7 @@ func TestNewInspectCmd(t *testing.T) { assert.Equal(t, tc.wants.DigestAlgorithm, opts.DigestAlgorithm) assert.NotNil(t, opts.OCIClient) assert.NotNil(t, opts.Logger) + assert.Equal(t, tc.wantsExporter, opts.exporter != nil) }) } } diff --git a/pkg/cmd/attestation/verify/verify_test.go b/pkg/cmd/attestation/verify/verify_test.go index 0cd5e22ee..02c28fd27 100644 --- a/pkg/cmd/attestation/verify/verify_test.go +++ b/pkg/cmd/attestation/verify/verify_test.go @@ -41,10 +41,11 @@ func TestNewVerifyCmd(t *testing.T) { } testcases := []struct { - name string - cli string - wants Options - wantsErr bool + name string + cli string + wants Options + wantsErr bool + wantsExporter bool }{ { name: "Invalid digest-alg flag", @@ -166,6 +167,20 @@ func TestNewVerifyCmd(t *testing.T) { }, wantsErr: true, }, + { + name: "Prints output in JSON format", + cli: "../test/data/sigstore-js-2.1.0.tgz --bundle ../test/data/sigstore-js-2.1.0-bundle.json --owner sigstore --format json", + wants: Options{ + ArtifactPath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0.tgz"), + BundlePath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json"), + DigestAlgorithm: "sha256", + Limit: 30, + OIDCIssuer: GitHubOIDCIssuer, + Owner: "sigstore", + SANRegex: "^https://github.com/sigstore/", + }, + wantsExporter: true, + }, } for _, tc := range testcases { @@ -204,6 +219,7 @@ func TestNewVerifyCmd(t *testing.T) { assert.NotNil(t, opts.APIClient) assert.NotNil(t, opts.Logger) assert.NotNil(t, opts.OCIClient) + assert.Equal(t, tc.wantsExporter, opts.exporter != nil) }) } }