Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Increase print test coverage #1411

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions cmd/oras/internal/output/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,49 @@ func (mw *mockWriter) String() string {
func TestPrint_Error(t *testing.T) {
TerryHowe marked this conversation as resolved.
Show resolved Hide resolved
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) {
TerryHowe marked this conversation as resolved.
Show resolved Hide resolved
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) {
TerryHowe marked this conversation as resolved.
Show resolved Hide resolved
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 + ">")
}
}
Loading