Skip to content

Commit

Permalink
chore: integrate sqllite tests
Browse files Browse the repository at this point in the history
chore: cleanup
  • Loading branch information
oneEyedSunday committed Oct 7, 2024
1 parent 2d53bd1 commit 7c23b42
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 21 deletions.
1 change: 0 additions & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
push:
branches:
- main
- feat/sqllite3_support

jobs:

Expand Down
1 change: 0 additions & 1 deletion .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: golangci-lint
on:
pull_request:
push:
jobs:
golangci:
name: lint
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ tidy_dependencies:
go mod tidy

migrate:
migrate -path ./datastore/postgres/migrations/ -database "postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable" up
migrate -path ./datastore/sql/migrations/ -database "postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable" up

migrate-down:
migrate -path ./datastore/postgres/migrations/ -database "postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable" down
migrate -path ./datastore/sql/migrations/ -database "postgres://sdump:sdump@localhost:3432/sdump?sslmode=disable" down

run-http:
go run cmd/*.go
Expand Down
26 changes: 25 additions & 1 deletion datastore/sql/ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func TestIngestRepository_Create(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

ingestStore := NewIngestRepository(client)
Expand All @@ -31,3 +31,27 @@ func TestIngestRepository_Create(t *testing.T) {
},
}))
}

func TestIngestRepository_Sqllite_Create(t *testing.T) {
client, teardownFunc := setupSqlliteDatabase(t)
defer teardownFunc()

ingestStore := NewIngestRepository(client)

urlStore := NewURLRepositoryTable(client)

// the models use uuid, tricky bit now is setting up sqlite3 uuid support
// This currently fails as the migrations fail

endpoint, err := urlStore.Get(context.Background(), &sdump.FindURLOptions{
Reference: "cmltfm6g330l5l1vq110", // see fixtures/urls.yml
})
require.NoError(t, err)

require.NoError(t, ingestStore.Create(context.Background(), &sdump.IngestHTTPRequest{
UrlID: endpoint.ID,
Request: sdump.RequestDefinition{
Body: "{}",
},
}))
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//go:build integration
// +build integration

package postgres
package sql

import (
"context"
"database/sql"
"fmt"
"testing"

sdumpPostgres "github.com/adelowo/sdump/datastore/postgres"
testfixtures "github.com/go-testfixtures/testfixtures/v3"
"github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/database/postgres"
Expand All @@ -19,7 +20,7 @@ import (
"github.com/uptrace/bun"
)

func prepareTestDatabase(t *testing.T, dsn string) {
func preparePostgresTestDatabase(t *testing.T, dsn string) {
t.Helper()

var err error
Expand Down Expand Up @@ -50,9 +51,9 @@ func prepareTestDatabase(t *testing.T, dsn string) {
require.NoError(t, fixtures.Load())
}

// setupDatabase spins up a new Postgres container and returns a closure
// setupPostgresDatabase spins up a new Postgres container and returns a closure
// please always make sure to call the closure as it is the teardown function
func setupDatabase(t *testing.T) (*bun.DB, func()) {
func setupPostgresDatabase(t *testing.T) (*bun.DB, func()) {
t.Helper()

var dsn string
Expand Down Expand Up @@ -83,9 +84,9 @@ func setupDatabase(t *testing.T) (*bun.DB, func()) {
dsn = fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=disable", "sdump", "sdump",
fmt.Sprintf("localhost:%s", port.Port()), "sdumptest")

prepareTestDatabase(t, dsn)
preparePostgresTestDatabase(t, dsn)

client, err := New(dsn, false)
client, err := sdumpPostgres.New(dsn, false)
require.NoError(t, err)

return client, func() {
Expand Down
11 changes: 6 additions & 5 deletions datastore/sqlite/sqlite_test.go → datastore/sql/sqlite_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//go:build integration
// +build integration

package sqlite
package sql

import (
"database/sql"
"fmt"
"testing"

sdumpSqllite "github.com/adelowo/sdump/datastore/sqlite"
testfixtures "github.com/go-testfixtures/testfixtures/v3"
"github.com/stretchr/testify/require"
"github.com/uptrace/bun"
Expand All @@ -17,7 +18,7 @@ import (
"github.com/golang-migrate/migrate/v4/database/sqlite3"
)

func prepareTestDatabase(t *testing.T, dsn string) {
func prepareSqlliteTestDatabase(t *testing.T, dsn string) {
t.Helper()

var err error
Expand Down Expand Up @@ -48,14 +49,14 @@ func prepareTestDatabase(t *testing.T, dsn string) {
require.NoError(t, fixtures.Load())
}

func setupDatabase(t *testing.T) (*bun.DB, func()) {
func setupSqlliteDatabase(t *testing.T) (*bun.DB, func()) {
t.Helper()

dsn := "file::memory:?cache=shared"

prepareTestDatabase(t, dsn)
prepareSqlliteTestDatabase(t, dsn)

client, err := New(dsn, false)
client, err := sdumpSqllite.New(dsn, false)
require.NoError(t, err)

return client, func() {
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions datastore/sql/url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var userID = uuid.MustParse("8511ac86-5079-42ae-a030-cb46e6dbfbda")

func TestURLRepositoryTable_Create(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

urlStore := NewURLRepositoryTable(client)
Expand All @@ -26,7 +26,7 @@ func TestURLRepositoryTable_Create(t *testing.T) {
}

func TestURLRepositoryTable_Get(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

urlStore := NewURLRepositoryTable(client)
Expand All @@ -44,7 +44,7 @@ func TestURLRepositoryTable_Get(t *testing.T) {
}

func TestURLRepositoryTable_Latest(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

urlStore := NewURLRepositoryTable(client)
Expand Down
4 changes: 2 additions & 2 deletions datastore/sql/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// var userID = uuid.MustParse("8511ac86-5079-42ae-a030-cb46e6dbfbda")

func TestUserRepository_Create(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

userStore := NewUserRepositoryTable(client)
Expand All @@ -27,7 +27,7 @@ func TestUserRepository_Create(t *testing.T) {
}

func TestUserRepository_Find(t *testing.T) {
client, teardownFunc := setupDatabase(t)
client, teardownFunc := setupPostgresDatabase(t)
defer teardownFunc()

userStore := NewUserRepositoryTable(client)
Expand Down

0 comments on commit 7c23b42

Please sign in to comment.