File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -718,3 +718,38 @@ func TestRunQueryWithExpectedErrorMeetsExpectations(t *testing.T) {
718718 t .Fatalf ("all expectations should be met: %s" , err )
719719 }
720720}
721+
722+ func TestEmptyRowSet (t * testing.T ) {
723+ t .Parallel ()
724+ db , mock , err := New ()
725+ if err != nil {
726+ t .Errorf ("an error '%s' was not expected when opening a stub database connection" , err )
727+ }
728+ defer db .Close ()
729+
730+ rs := NewRows ([]string {"id" , "title" })
731+
732+ mock .ExpectQuery ("SELECT (.+) FROM articles WHERE id = ?" ).
733+ WithArgs (5 ).
734+ WillReturnRows (rs )
735+
736+ rows , err := db .Query ("SELECT (.+) FROM articles WHERE id = ?" , 5 )
737+ if err != nil {
738+ t .Errorf ("error '%s' was not expected while retrieving mock rows" , err )
739+ }
740+
741+ defer func () {
742+ if er := rows .Close (); er != nil {
743+ t .Error ("Unexpected error while trying to close rows" )
744+ }
745+ }()
746+
747+ if rows .Next () {
748+ t .Error ("expected no rows but got one" )
749+ }
750+
751+ err = mock .ExpectationsWereMet ()
752+ if err != nil {
753+ t .Fatalf ("all expectations should be met: %s" , err )
754+ }
755+ }
You can’t perform that action at this time.
0 commit comments