feat(trace): add trace test helpers (#3108)

This commit is contained in:
cong
2023-04-08 22:52:25 +08:00
committed by GitHub
parent 189e9bd9da
commit 22fad4bb9c
6 changed files with 217 additions and 32 deletions

View File

@@ -8,6 +8,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/trace/tracetest"
)
const mockedDatasource = "sqlmock"
@@ -17,6 +18,7 @@ func init() {
}
func TestSqlConn(t *testing.T) {
me := tracetest.NewInMemoryExporter(t)
mock, err := buildConn()
assert.Nil(t, err)
mock.ExpectExec("any")
@@ -49,6 +51,7 @@ func TestSqlConn(t *testing.T) {
assert.NotNil(t, badConn.Transact(func(session Session) error {
return nil
}))
assert.Equal(t, 14, len(me.GetSpans()))
}
func buildConn() (mock sqlmock.Sqlmock, err error) {