Skip to content

Commit

Permalink
add sql collector test
Browse files Browse the repository at this point in the history
  • Loading branch information
xgfone committed Aug 8, 2024
1 parent c14b22f commit 3d21b12
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions interceptor_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 xgfone
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sqlx

import (
"reflect"
"slices"
"testing"
)

func TestSqlCollector(t *testing.T) {
collector := NewSqlCollector()
_, _, _ = collector.Intercept("sql0", nil)

collector.SetEnabled(true)
_, _, _ = collector.Intercept("sql1", nil)

collector.SetEnableFunc(func() bool { return false })
_, _, _ = collector.Intercept("sql2", nil)

collector.SetEnableFunc(nil)
interceptors := Interceptors{collector}
_, _, _ = interceptors.Intercept("sql3", nil)

excepts := []string{"sql1", "sql3"}
sqls := collector.Sqls()
slices.Sort(sqls)
if !reflect.DeepEqual(excepts, sqls) {
t.Errorf("expects %v, but got %v", excepts, sqls)
}
}

0 comments on commit 3d21b12

Please sign in to comment.