Skip to content

Commit

Permalink
Use enttest helpers for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidNix committed Nov 26, 2023
1 parent f8c7abd commit 8b90ba4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
6 changes: 6 additions & 0 deletions ent/enttest/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package enttest

const (
Driver = "sqlite3"
URL = "file:test?mode=memory&cache=shared&_fk=1"
)
19 changes: 2 additions & 17 deletions server/app_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package server

import (
"context"
"io"
"log/slog"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/DavidNix/indie/ent"
"github.com/DavidNix/indie/ent/enttest"
"github.com/labstack/echo/v4"
_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/require"
Expand All @@ -20,24 +19,10 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}

func setupDatabase(t require.TestingT) *ent.Client {
const (
driver = "sqlite3"
dbURL = "file:indie?mode=memory&cache=shared&_fk=1"
)
client, err := ent.Open(driver, dbURL)
require.NoError(t, err)

err = client.Schema.Create(context.Background())
require.NoError(t, err)

return client
}

func TestExample(t *testing.T) {
t.Parallel()

client := setupDatabase(t)
client := enttest.Open(t, enttest.Driver, enttest.URL)

app := NewApp(client)

Expand Down

0 comments on commit 8b90ba4

Please sign in to comment.