Skip to content

Commit

Permalink
add ExampleRows_values()
Browse files Browse the repository at this point in the history
  • Loading branch information
pashagolub committed Aug 11, 2022
1 parent a33db28 commit 1a81a6c
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,35 @@ func TestQuerySingleRow(t *testing.T) {
}
}

func ExampleRows_values() {
// t.Parallel()
mock, err := NewConn()
if err != nil {
fmt.Println("failed to open pgxmock database:", err)
}
defer mock.Close(context.Background())

rows := NewRows([]string{"raw"}).
AddRow(`one string value with some text!`).
AddRow(`two string value with even more text than the first one`).
AddRow([]byte{})
mock.ExpectQuery("SELECT").WillReturnRows(rows)

rs, err := mock.Query(context.Background(), "SELECT")
if err != nil {
fmt.Print(err)
}
defer rs.Close()

for rs.Next() {
v, e := rs.Values()
fmt.Println(v[0], e)
}
// Output: one string value with some text! <nil>
// two string value with even more text than the first one <nil>
// [] <nil>
}

func ExampleRows_rawValues() {
// t.Parallel()
mock, err := NewConn()
Expand Down

0 comments on commit 1a81a6c

Please sign in to comment.