Skip to content

Commit

Permalink
fix: apply test recommendations
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
  • Loading branch information
TerryHowe committed Dec 4, 2024
1 parent 7692fbc commit 779e5d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
9 changes: 5 additions & 4 deletions cmd/oras/internal/display/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package display
import (
"oras.land/oras/internal/testutils"
"os"
"reflect"
"testing"

"oras.land/oras/cmd/oras/internal/display/metadata/text"
Expand All @@ -28,7 +29,7 @@ import (

func TestNewPushHandler(t *testing.T) {
mockFetcher := testutils.NewMockFetcher()
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewPushHandler(printer, option.Format{Type: option.FormatTypeText.Name}, os.Stdout, mockFetcher.Fetcher)
if err != nil {
t.Errorf("NewPushHandler() error = %v, want nil", err)
Expand All @@ -37,23 +38,23 @@ func TestNewPushHandler(t *testing.T) {

func TestNewAttachHandler(t *testing.T) {
mockFetcher := testutils.NewMockFetcher()
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewAttachHandler(printer, option.Format{Type: option.FormatTypeText.Name}, os.Stdout, mockFetcher.Fetcher)
if err != nil {
t.Errorf("NewAttachHandler() error = %v, want nil", err)
}
}

func TestNewPullHandler(t *testing.T) {
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
_, _, err := NewPullHandler(printer, option.Format{Type: option.FormatTypeText.Name}, "", os.Stdout)
if err != nil {
t.Errorf("NewPullHandler() error = %v, want nil", err)
}
}

func TestNewCopyHandler(t *testing.T) {
printer := output.NewPrinter(os.Stdout, os.Stderr, false)
printer := output.NewPrinter(os.Stdout, os.Stderr)
copyHandler, copyMetadataHandler := NewCopyHandler(printer, os.Stdout, nil)
if _, ok := copyHandler.(*status.TTYCopyHandler); !ok {
t.Errorf("expected *status.TTYCopyHandler actual %v", reflect.TypeOf(copyHandler))
Expand Down
8 changes: 5 additions & 3 deletions cmd/oras/internal/display/status/tty_console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ limitations under the License.
package status

import (
"strconv"
"testing"

"oras.land/oras-go/v2"
"oras.land/oras-go/v2/content/memory"
"oras.land/oras/internal/testutils"
"testing"
)

type testGraphTarget struct {
Expand Down Expand Up @@ -117,13 +119,13 @@ func TestTTYCopyHandler_OnCopySkipped(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer ch.StopTracking()

if err = ch.OnCopySkipped(ctx, mockFetcher.OciImage); err != nil {
t.Errorf("OnCopySkipped() should not return an error: %v", err)
}

if err = testutils.MatchPty(pty, slave, "\x1b[?25l\x1b7\x1b[0m"); err != nil {
ch.StopTracking()

Check failure on line 127 in cmd/oras/internal/display/status/tty_console_test.go

View workflow job for this annotation

GitHub Actions / lint (1.23)

Error return value of `ch.StopTracking` is not checked (errcheck)
if err = testutils.MatchPty(pty, slave, "Exists", mockFetcher.OciImage.MediaType, strconv.FormatInt(mockFetcher.OciImage.Size, 10), "100%"); err != nil {
t.Fatal(err)
}
}
Expand Down
9 changes: 2 additions & 7 deletions cmd/oras/root/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"oras.land/oras/cmd/oras/internal/display/status"
"oras.land/oras/cmd/oras/internal/output"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -131,11 +129,10 @@ func Test_doCopy(t *testing.T) {
defer slave.Close()
var opts copyOptions
opts.TTY = slave
opts.Verbose = true
opts.From.Reference = memDesc.Digest.String()
dst := memory.New()
builder := &strings.Builder{}
printer := output.NewPrinter(builder, os.Stderr, opts.Verbose)
printer := output.NewPrinter(builder, os.Stderr)
handler := status.NewTextCopyHandler(printer, dst)
// test
_, err = doCopy(context.Background(), handler, memStore, dst, &opts)
Expand All @@ -157,11 +154,10 @@ func Test_doCopy_skipped(t *testing.T) {
defer slave.Close()
var opts copyOptions
opts.TTY = slave
opts.Verbose = true
opts.From.Reference = memDesc.Digest.String()
dst := memory.New()
builder := &strings.Builder{}
printer := output.NewPrinter(builder, os.Stderr, opts.Verbose)
printer := output.NewPrinter(builder, os.Stderr)
handler := status.NewTextCopyHandler(printer, dst)

// test
Expand All @@ -184,7 +180,6 @@ func Test_doCopy_mounted(t *testing.T) {
defer slave.Close()
var opts copyOptions
opts.TTY = slave
opts.Verbose = true
opts.From.Reference = manifestDigest
// mocked repositories
from, err := remote.NewRepository(fmt.Sprintf("%s/%s", host, repoFrom))
Expand Down

0 comments on commit 779e5d8

Please sign in to comment.