Skip to content

Commit

Permalink
chore(test): Test_queryExecutor improved
Browse files Browse the repository at this point in the history
  • Loading branch information
trakhimenok committed Aug 20, 2023
1 parent 0d0b731 commit 9173ad6
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions dal/query_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func Test_selector_QueryAllRecords(t *testing.T) {
}
}

func Test_queryExecutor_QueryAllRecords(t *testing.T) {
func Test_queryExecutor(t *testing.T) {
type args struct {
c context.Context
query Query
Expand Down Expand Up @@ -131,20 +131,32 @@ func Test_queryExecutor_QueryAllRecords(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.shouldPanic {
defer func() {
if r := recover(); r == nil {
t.Errorf("QueryAllRecords() should have panicked!")
}
}()
}
got, err := tt.qe.QueryAllRecords(tt.args.c, tt.args.query)
if tt.wantErr(t, err, fmt.Sprintf("QueryReader(%v, %v)", tt.args.c, tt.args.query)) {
return
}
if err == nil {
assert.Nil(t, got)
runTest := func(t *testing.T, execut func() (any, error)) {
if tt.shouldPanic {
defer func() {
if r := recover(); r == nil {
t.Errorf("QueryAllRecords() should have panicked!")
}
}()
}
got, err := execut()
if tt.wantErr(t, err, fmt.Sprintf("QueryReader(%v, %v)", tt.args.c, tt.args.query)) {
return
}
if err == nil {
assert.Nil(t, got)
}
}
t.Run("QueryAllRecords", func(t *testing.T) {
runTest(t, func() (any, error) {
return tt.qe.QueryAllRecords(tt.args.c, tt.args.query)
})
})
t.Run("QueryReader", func(t *testing.T) {
runTest(t, func() (any, error) {
return tt.qe.QueryReader(tt.args.c, tt.args.query)
})
})
})
}
}

0 comments on commit 9173ad6

Please sign in to comment.