Skip to content

Commit

Permalink
Fix printer test
Browse files Browse the repository at this point in the history
  • Loading branch information
lotusirous committed Oct 29, 2022
1 parent 1480585 commit b196755
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type RowRenderer interface {
AddRow(field, value string)
// AddRowMap appends the row by map input.
AddRowMap(values map[string]string)
// Render the rows.
Render()
// RenderTo the rows.
RenderTo(w io.Writer)
}

// NewRowRender creates the printer.
Expand Down Expand Up @@ -49,7 +49,7 @@ func (p *pw) AddRowMap(values map[string]string) {
}

// Render the rows to output
func (p *pw) Render() {
func (p *pw) RenderTo(w io.Writer) {
for _, l := range p.rows {
fmt.Fprintf(p.w, "%s: %s\n", strings.ToUpper(l[0]), l[1])
}
Expand Down
7 changes: 3 additions & 4 deletions printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import (
func TestRowPrinter(t *testing.T) {
buf := new(bytes.Buffer)
pw := &pw{buf, make([][]string, 0)}
pw.AddRow("foo", "bar")
pw.Render()
pw.AddRow("FILE", "bar")
pw.RenderTo(buf)

got := buf.String()
want := "FOO: bar\n"
want := "FILE: bar\n"

if got != want {
t.Errorf("Got: %s - want: %s", buf, want)
}

}

0 comments on commit b196755

Please sign in to comment.