Skip to content

Commit

Permalink
use go-sqlmock instead of sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
lvrach committed Sep 26, 2024
1 parent a116ae2 commit 4034aaf
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 6 additions & 4 deletions stats/collectors/sqldb_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package collectors_test

import (
"database/sql"
"testing"

_ "github.com/mattn/go-sqlite3" // Import the SQLite driver
"github.com/DATA-DOG/go-sqlmock"

"github.com/stretchr/testify/require"

Expand All @@ -14,8 +13,11 @@ import (
)

func TestSQLDatabase(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
require.NoError(t, err)
db, _, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()

m, err := memstats.New()
require.NoError(t, err)
Expand Down
9 changes: 6 additions & 3 deletions stats/otel_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stats_test

import (
"context"
"database/sql"
"fmt"
"net/http"
"os"
Expand All @@ -11,6 +10,7 @@ import (
"testing"
"time"

"github.com/DATA-DOG/go-sqlmock"
promClient "github.com/prometheus/client_model/go"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -154,8 +154,11 @@ func TestOTelPeriodicStats(t *testing.T) {
})

t.Run("sql collector", func(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
require.NoError(t, err)
db, _, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()

runTest(t,
[]expectation{
Expand Down
10 changes: 6 additions & 4 deletions stats/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package stats_test

import (
"context"
"database/sql"
"fmt"
"io"
"net"
Expand All @@ -14,7 +13,7 @@ import (
"testing"
"time"

_ "github.com/mattn/go-sqlite3"
"github.com/DATA-DOG/go-sqlmock"
"github.com/stretchr/testify/require"

"github.com/rudderlabs/rudder-go-kit/config"
Expand Down Expand Up @@ -452,8 +451,11 @@ func TestStatsdRegisterCollector(t *testing.T) {
})

t.Run("sql collector", func(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
require.NoError(t, err)
db, _, err := sqlmock.New()
if err != nil {
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
}
defer db.Close()

runTest(t,
[]string{
Expand Down

0 comments on commit 4034aaf

Please sign in to comment.