Skip to content

Commit

Permalink
Add helpers for unit tests for snowflake custom driver
Browse files Browse the repository at this point in the history
  • Loading branch information
amanangira committed Mar 24, 2024
1 parent fed1054 commit ba0f69b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions xray/sqlcontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
package xray

import (
"context"
"database/sql/driver"
"encoding/json"
"errors"
"testing"
Expand Down Expand Up @@ -44,6 +46,24 @@ func mockOracle(mock sqlmock.Sqlmock, err error) {
mock.ExpectPrepare(`SELECT version FROM v\$instance UNION SELECT user, ora_database_name FROM dual`).ExpectQuery().WillReturnRows(row)
}

func mockSnowflakeDB(mock sqlmock.Sqlmock, err error) {
row := sqlmock.NewRows([]string{"current_version()", "current_user()", "current_database()"}).
AddRow("test version", "test user", "test database").
RowError(0, err)
mock.ExpectPrepare(`SELECT current_version\(\), current_user\(\), current_database\(\)`).ExpectQuery().WillReturnRows(row)
}

func registerSnowflakeDriver() {
RegisterSQLDetector("snowflake", func(ctx context.Context, conn driver.Conn, attr *DBAttribute) error {
attr.DatabaseType = "Snowflake"
return queryRow(
ctx, conn,
"SELECT current_version(), current_user(), current_database()",
&attr.DatabaseVersion, &attr.User, &attr.DBname,
)
})
}

func capturePing(dsn string) (*Segment, error) {
ctx, td := NewTestDaemon()
defer td.Close()
Expand Down

0 comments on commit ba0f69b

Please sign in to comment.