Skip to content

Commit 5fa5229

Browse files
committed
Updating and simplifying tests
1 parent ed01238 commit 5fa5229

File tree

1 file changed

+5
-17
lines changed

1 file changed

+5
-17
lines changed

querysql/querysql_test.go

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func isClosed(r *sql.Rows) bool {
2727
return err != nil && err.Error() == "sql: Rows are closed"
2828
}
2929

30+
// TODO(dsf): Expand to test std logger
3031
func TestMultipleRowsetsResultsHappyDay(t *testing.T) {
3132
qry := `
3233
-- single scalar
@@ -144,6 +145,7 @@ select _function='OtherTestFunction', time=42, money=convert(money, 12345.67);
144145

145146
}
146147

148+
// TODO(dsf): Also test the std logger
147149
func TestInvalidLogLevel(t *testing.T) {
148150
qry := `
149151
-- log something
@@ -218,16 +220,13 @@ select 2;
218220

219221
func TestDispatcherSetupError(t *testing.T) {
220222
var mustNotBeTrue bool
221-
var hook LogHook
222-
logger := logrus.StandardLogger()
223-
logger.Hooks.Add(&hook)
224223
defer func() {
225224
r := recover()
226225
assert.NotNil(t, r) // nil if a panic didn't happen, not nil if a panic happened
227226
assert.False(t, mustNotBeTrue)
228227
}()
229228

230-
ctx := querysql.WithLogger(context.Background(), querysql.LogrusMSSQLLogger(logger, logrus.InfoLevel))
229+
ctx := context.Background()
231230
ctx = querysql.WithDispatcher(ctx, querysql.GoMSSQLDispatcher([]interface{}{
232231
"SomethingThatIsNotAFunctionPointer", // This should cause a panic
233232
}))
@@ -724,19 +723,13 @@ create table MyUsers (
724723
);
725724
insert into MyUsers (Username) values ('JohnDoe');
726725
727-
-- logging
728-
select _log='info', Y = 'one';
729-
730726
-- dispatcher
731727
select _function='TestFunction', component = 'abc', val=1, time=1.23;
732728
733729
select _function='ReturnAnonFunc', label = 'myLabel', time=1.23;
734730
`
735731

736-
var hook LogHook
737-
logger := logrus.StandardLogger()
738-
logger.Hooks.Add(&hook)
739-
ctx := querysql.WithLogger(context.Background(), querysql.LogrusMSSQLLogger(logger, logrus.InfoLevel))
732+
ctx := context.Background()
740733
ctx = querysql.WithDispatcher(ctx, querysql.GoMSSQLDispatcher([]interface{}{
741734
testhelper.TestFunction,
742735
testhelper.ReturnAnonFunc("myComponent"),
@@ -748,11 +741,6 @@ select _function='ReturnAnonFunc', label = 'myLabel', time=1.23;
748741

749742
assert.True(t, testhelper.TestFunctionsCalled["ReturnAnonFunc.myComponent"])
750743

751-
// Check that we have exhausted the logging select before we do the call that gets ErrNoMoreSets
752-
assert.Equal(t, []logrus.Fields{
753-
{"Y": "one"},
754-
}, hook.lines)
755-
756744
assert.True(t, testhelper.TestFunctionsCalled["TestFunction"])
757745
}
758746

@@ -767,7 +755,7 @@ func TestDispatcherPanicsWithTwoAnonFuncs(t *testing.T) {
767755
assert.False(t, mustNotBeTrue)
768756
}()
769757

770-
ctx := querysql.WithLogger(context.Background(), querysql.LogrusMSSQLLogger(logger, logrus.InfoLevel))
758+
ctx := context.Background()
771759
ctx = querysql.WithDispatcher(ctx, querysql.GoMSSQLDispatcher([]interface{}{
772760
testhelper.ReturnAnonFunc("myComponent"),
773761
testhelper.ReturnAnonFunc("myComponent2"), // This should cause a panic

0 commit comments

Comments
 (0)