diff --git a/pkg/cmd/attestation/inspect/inspect_integration_test.go b/pkg/cmd/attestation/inspect/inspect_integration_test.go index f38d0244e..6c56461af 100644 --- a/pkg/cmd/attestation/inspect/inspect_integration_test.go +++ b/pkg/cmd/attestation/inspect/inspect_integration_test.go @@ -9,67 +9,37 @@ import ( "strings" "testing" - "github.com/cli/cli/v2/pkg/cmd/attestation/verification" "github.com/cli/cli/v2/pkg/cmdutil" - - //"github.com/cli/cli/v2/pkg/httpmock" "github.com/cli/cli/v2/pkg/iostreams" "github.com/stretchr/testify/assert" ) -func TestNewInspectCmd(t *testing.T) { +func TestNewInspectCmd_PrintOutputJSONFormat(t *testing.T) { testIO, _, _, _ := iostreams.Test() f := &cmdutil.Factory{ IOStreams: testIO, HttpClient: func() (*http.Client, error) { - //reg := &httpmock.Registry{} - client := http.DefaultClient - //httpmock.ReplaceTripper(client, reg) - return client, nil + return http.DefaultClient, nil }, } - testcases := []struct { - name string - cli string - wants Options - wantsErr bool - wantsExporter bool - }{ - { - name: "Prints output in JSON format", - cli: fmt.Sprintf("%s --format json", bundlePath), - wants: Options{ - BundlePath: bundlePath, - SigstoreVerifier: verification.NewMockSigstoreVerifier(t), - }, - wantsExporter: true, - }, - } - - for _, tc := range testcases { - t.Run(tc.name, func(t *testing.T) { - var opts *Options - cmd := NewInspectCmd(f, func(o *Options) error { - opts = o - return nil - }) - - argv := strings.Split(tc.cli, " ") - cmd.SetArgs(argv) - cmd.SetIn(&bytes.Buffer{}) - cmd.SetOut(&bytes.Buffer{}) - cmd.SetErr(&bytes.Buffer{}) - _, err := cmd.ExecuteC() - if tc.wantsErr { - assert.Error(t, err) - return - } - assert.NoError(t, err) - - assert.Equal(t, tc.wants.BundlePath, opts.BundlePath) - assert.NotNil(t, opts.Logger) - assert.Equal(t, tc.wantsExporter, opts.exporter != nil) + t.Run("Print output in JSON format", func(t *testing.T) { + var opts *Options + cmd := NewInspectCmd(f, func(o *Options) error { + opts = o + return nil }) - } + + argv := strings.Split(fmt.Sprintf("%s --format json", bundlePath), " ") + cmd.SetArgs(argv) + cmd.SetIn(&bytes.Buffer{}) + cmd.SetOut(&bytes.Buffer{}) + cmd.SetErr(&bytes.Buffer{}) + _, err := cmd.ExecuteC() + assert.NoError(t, err) + + assert.Equal(t, bundlePath, opts.BundlePath) + assert.NotNil(t, opts.Logger) + assert.NotNil(t, opts.exporter) + }) } diff --git a/pkg/cmd/attestation/inspect/inspect_test.go b/pkg/cmd/attestation/inspect/inspect_test.go index c1bc1c72c..c94e80ad2 100644 --- a/pkg/cmd/attestation/inspect/inspect_test.go +++ b/pkg/cmd/attestation/inspect/inspect_test.go @@ -21,9 +21,7 @@ const ( SigstoreSanRegex = "^https://github.com/sigstore/sigstore-js/" ) -var ( - bundlePath = test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json") -) +var bundlePath = test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0-bundle.json") func TestRunInspect(t *testing.T) { opts := Options{