add tests for json output

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2024-03-18 11:37:29 -06:00
parent b5ffcf116d
commit 12c7de2559
2 changed files with 37 additions and 8 deletions

View file

@ -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)
})
}
}

View file

@ -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)
})
}
}