use the iostreams.Test helper func
Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
parent
b8c9f96da7
commit
be6b042039
6 changed files with 10 additions and 37 deletions
|
|
@ -18,7 +18,7 @@ func NewClientWithMockGHClient(hasNextPage bool) Client {
|
|||
fetcher := mockDataGenerator{
|
||||
NumAttestations: 5,
|
||||
}
|
||||
l := logging.NewSystemLogger()
|
||||
l := logging.NewTestLogger()
|
||||
|
||||
if hasNextPage {
|
||||
return &LiveClient{
|
||||
|
|
@ -138,7 +138,7 @@ func TestGetByDigest_NoAttestationsFound(t *testing.T) {
|
|||
api: mockAPIClient{
|
||||
OnRESTWithNext: fetcher.OnRESTWithNextNoAttestations,
|
||||
},
|
||||
logger: logging.NewSystemLogger(),
|
||||
logger: logging.NewTestLogger(),
|
||||
}
|
||||
|
||||
attestations, err := c.GetByRepoAndDigest(testRepo, testDigest, DefaultLimit)
|
||||
|
|
@ -161,7 +161,7 @@ func TestGetByDigest_Error(t *testing.T) {
|
|||
api: mockAPIClient{
|
||||
OnRESTWithNext: fetcher.OnRESTWithNextError,
|
||||
},
|
||||
logger: logging.NewSystemLogger(),
|
||||
logger: logging.NewTestLogger(),
|
||||
}
|
||||
|
||||
attestations, err := c.GetByRepoAndDigest(testRepo, testDigest, DefaultLimit)
|
||||
|
|
|
|||
|
|
@ -10,15 +10,11 @@ import (
|
|||
"github.com/cli/cli/v2/pkg/cmd/attestation/artifact"
|
||||
"github.com/cli/cli/v2/pkg/cmd/attestation/artifact/oci"
|
||||
"github.com/cli/cli/v2/pkg/cmd/attestation/logging"
|
||||
"github.com/cli/cli/v2/pkg/cmd/attestation/test"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunDownload(t *testing.T) {
|
||||
res := test.SuppressAndRestoreOutput()
|
||||
defer res()
|
||||
|
||||
tempDir, err := os.MkdirTemp("", "gh-attestation-test")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
|
@ -30,7 +26,7 @@ func TestRunDownload(t *testing.T) {
|
|||
DigestAlgorithm: "sha512",
|
||||
OutputPath: tempDir,
|
||||
Limit: 30,
|
||||
Logger: logging.NewSystemLogger(),
|
||||
Logger: logging.NewTestLogger(),
|
||||
}
|
||||
|
||||
t.Run("fetch and store attestations successfully", func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -21,16 +21,11 @@ var (
|
|||
)
|
||||
|
||||
func TestRunInspect(t *testing.T) {
|
||||
res := test.SuppressAndRestoreOutput()
|
||||
defer res()
|
||||
|
||||
logger := logging.NewSystemLogger()
|
||||
|
||||
opts := Options{
|
||||
ArtifactPath: artifactPath,
|
||||
BundlePath: bundlePath,
|
||||
DigestAlgorithm: "sha512",
|
||||
Logger: logger,
|
||||
Logger: logging.NewTestLogger(),
|
||||
OCIClient: oci.NewMockClient(),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,8 +32,9 @@ func NewDefaultLogger(io *iostreams.IOStreams) *Logger {
|
|||
return NewLogger(io, isQuiet, isVerbose)
|
||||
}
|
||||
|
||||
func NewSystemLogger() *Logger {
|
||||
return NewDefaultLogger(iostreams.System())
|
||||
func NewTestLogger() *Logger {
|
||||
testIO, _, _, _ := iostreams.Test()
|
||||
return NewDefaultLogger(testIO)
|
||||
}
|
||||
|
||||
// Printf writes the formatted arguments to the stderr writer.
|
||||
|
|
|
|||
|
|
@ -1,16 +0,0 @@
|
|||
package test
|
||||
|
||||
import "os"
|
||||
|
||||
func SuppressAndRestoreOutput() func() {
|
||||
null, _ := os.Open(os.DevNull)
|
||||
stdOut := os.Stdout
|
||||
stdErr := os.Stderr
|
||||
os.Stdout = null
|
||||
os.Stderr = null
|
||||
return func() {
|
||||
defer null.Close()
|
||||
os.Stdout = stdOut
|
||||
os.Stderr = stdErr
|
||||
}
|
||||
}
|
||||
|
|
@ -21,10 +21,7 @@ const (
|
|||
)
|
||||
|
||||
func TestRunVerify(t *testing.T) {
|
||||
res := test.SuppressAndRestoreOutput()
|
||||
defer res()
|
||||
|
||||
logger := logging.NewSystemLogger()
|
||||
logger := logging.NewTestLogger()
|
||||
|
||||
publicGoodOpts := Options{
|
||||
ArtifactPath: test.NormalizeRelativePath("../test/data/sigstore-js-2.1.0.tgz"),
|
||||
|
|
@ -190,7 +187,7 @@ func TestVerifySLSAPredicateType_InvalidPredicate(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
err := verifySLSAPredicateType(logging.NewSystemLogger(), apr)
|
||||
err := verifySLSAPredicateType(logging.NewTestLogger(), apr)
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, ErrNoMatchingSLSAPredicate)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue