Skip to content

Commit

Permalink
add TestDisplayTSV test case
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdevivo committed Jul 20, 2021
1 parent 566af13 commit 89b40e0
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/display/display_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,45 @@ func TestDisplayCSV(t *testing.T) {
// TODO perhaps test the actual content of the lines?
}

func TestDisplayTSV(t *testing.T) {
db, mock, _ := sqlmock.New()

mockRows := sqlmock.NewRows([]string{"id", "name", "value"}).
AddRow("1", "name 1", "value 1").
AddRow("2", "name 2", "value 2").
AddRow("3", "name 3", "value 3")

mock.ExpectQuery("select").WillReturnRows(mockRows)

rows, _ := db.Query("select")

var b bytes.Buffer
err := WriteTo(rows, &b, "tsv", false)
if err != nil {
t.Fatal(err)
}

r := csv.NewReader(strings.NewReader(b.String()))
r.Comma = '\t'

records, err := r.ReadAll()
if err != nil {
t.Fatal(err)
}

lineCount := len(records)

if lineCount != 4 {
t.Fatalf("expected 4 lines of output, got: %d", lineCount)
}

if len(records[0]) != 3 {
t.Fatalf("expected 3 columns of output, got: %d", len(records[0]))
}

// TODO perhaps test the actual content of the lines?
}

func TestDisplayJSON(t *testing.T) {
db, mock, _ := sqlmock.New()

Expand Down

0 comments on commit 89b40e0

Please sign in to comment.