From 4c5d698b00d1a3420254df84437412c41bca8269 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Fri, 14 Jun 2024 12:54:57 -0600 Subject: [PATCH 1/4] chore: Increase print test coverage Signed-off-by: Terry Howe --- cmd/oras/internal/output/print_test.go | 42 +++++++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cmd/oras/internal/output/print_test.go b/cmd/oras/internal/output/print_test.go index f7873523b..a26c0018a 100644 --- a/cmd/oras/internal/output/print_test.go +++ b/cmd/oras/internal/output/print_test.go @@ -43,23 +43,49 @@ func (mw *mockWriter) String() string { func TestPrint_Error(t *testing.T) { mockWriter := &mockWriter{} printer := NewPrinter(mockWriter, false) - printer.Println("boom") + err := printer.Println("boom") if mockWriter.errorCount != 1 { t.Error("Expected one errors actual <" + strconv.Itoa(mockWriter.errorCount) + ">") } + if err != nil { + t.Error("Expected error to be ignored") + } } func TestPrint_NoError(t *testing.T) { - mockWriter := &mockWriter{} - printer := NewPrinter(mockWriter, false) + builder := &strings.Builder{} + printer := NewPrinter(builder, false) - expected := "blah blah" - printer.Println(expected) - actual := strings.TrimSpace(mockWriter.String()) + expected := "normal\n" + err := printer.Println("normal") + if err != nil { + t.Error("Expected no error got <" + err.Error() + ">") + } + err = printer.PrintVerbose("verbose") + if err != nil { + t.Error("Expected no error got <" + err.Error() + ">") + } + actual := builder.String() if expected != actual { t.Error("Expected <" + expected + "> not equal to actual <" + actual + ">") } - if mockWriter.errorCount != 0 { - t.Error("Expected no errors actual <" + strconv.Itoa(mockWriter.errorCount) + ">") +} + +func TestPrint_Verbose(t *testing.T) { + builder := &strings.Builder{} + printer := NewPrinter(builder, true) + + expected := "normal\nverbose\n" + err := printer.Println("normal") + if err != nil { + t.Error("Expected no error got <" + err.Error() + ">") + } + err = printer.PrintVerbose("verbose") + if err != nil { + t.Error("Expected no error got <" + err.Error() + ">") + } + actual := builder.String() + if expected != actual { + t.Error("Expected <" + expected + "> not equal to actual <" + actual + ">") } } From 7682d4d5241f5da989c42db16eb2bb60c58b0779 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Tue, 18 Jun 2024 05:39:37 -0600 Subject: [PATCH 2/4] Update cmd/oras/internal/output/print_test.go Co-authored-by: Billy Zha Signed-off-by: Terry Howe --- cmd/oras/internal/output/print_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/output/print_test.go b/cmd/oras/internal/output/print_test.go index a26c0018a..33765277b 100644 --- a/cmd/oras/internal/output/print_test.go +++ b/cmd/oras/internal/output/print_test.go @@ -71,7 +71,7 @@ func TestPrint_NoError(t *testing.T) { } } -func TestPrint_Verbose(t *testing.T) { +func TestPrinter_PrintVerbose(t *testing.T) { builder := &strings.Builder{} printer := NewPrinter(builder, true) From 6d55a8c798aa9e246994fb92f3ff9364af15abf3 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Tue, 18 Jun 2024 05:39:48 -0600 Subject: [PATCH 3/4] Update cmd/oras/internal/output/print_test.go Co-authored-by: Billy Zha Signed-off-by: Terry Howe --- cmd/oras/internal/output/print_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/output/print_test.go b/cmd/oras/internal/output/print_test.go index 33765277b..f3dca9340 100644 --- a/cmd/oras/internal/output/print_test.go +++ b/cmd/oras/internal/output/print_test.go @@ -52,7 +52,7 @@ func TestPrint_Error(t *testing.T) { } } -func TestPrint_NoError(t *testing.T) { +func TestPrinter_PrintVerbose_noError(t *testing.T) { builder := &strings.Builder{} printer := NewPrinter(builder, false) From f1ca71d6512a177f74afd351a75adb97ee291454 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Tue, 18 Jun 2024 05:39:57 -0600 Subject: [PATCH 4/4] Update cmd/oras/internal/output/print_test.go Co-authored-by: Billy Zha Signed-off-by: Terry Howe --- cmd/oras/internal/output/print_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/output/print_test.go b/cmd/oras/internal/output/print_test.go index f3dca9340..74d1f8eb3 100644 --- a/cmd/oras/internal/output/print_test.go +++ b/cmd/oras/internal/output/print_test.go @@ -40,7 +40,7 @@ func (mw *mockWriter) String() string { return mw.written } -func TestPrint_Error(t *testing.T) { +func TestPrinter_Println(t *testing.T) { mockWriter := &mockWriter{} printer := NewPrinter(mockWriter, false) err := printer.Println("boom")