Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
773759739d |
No files matched your search
@@ -3342,6 +3342,7 @@ neoirc/
|
|||||||
│ │ └── schema/
|
│ │ └── schema/
|
||||||
│ │ ├── 000.sql # schema_migrations bootstrap
|
│ │ ├── 000.sql # schema_migrations bootstrap
|
||||||
│ │ └── 001_initial.sql
|
│ │ └── 001_initial.sql
|
||||||
|
│ ├── dbtest/ # Gives each test its own database; only tests import it
|
||||||
│ ├── globals/ # Application-wide metadata
|
│ ├── globals/ # Application-wide metadata
|
||||||
│ │ └── globals.go
|
│ │ └── globals.go
|
||||||
│ ├── handlers/ # HTTP request handlers
|
│ ├── handlers/ # HTTP request handlers
|
||||||
|
|||||||
@@ -156,15 +156,15 @@ func TestForeignKeysOnAfterCancelledQuery(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestNewTestDatabaseURLKeepsDataAfterCancelledQuery cancels a query
|
// TestNewURLKeepsDataAfterCancelledQuery cancels a query on a test
|
||||||
// on a test database while it runs, which makes the pool close its
|
// database while it runs, which makes the pool close its only
|
||||||
// only connection and open a new one. A TEMP table lasts only as long
|
// connection and open a new one. A TEMP table lasts only as long as
|
||||||
// as its connection, so its absence shows the connection was replaced.
|
// its connection, so its absence shows the connection was replaced.
|
||||||
// The database must still have its tables and rows.
|
// The database must still have its tables and rows.
|
||||||
func TestNewTestDatabaseURLKeepsDataAfterCancelledQuery(t *testing.T) {
|
func TestNewURLKeepsDataAfterCancelledQuery(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
database, err := startDatabase(t, dbtest.NewTestDatabaseURL(t))
|
database, err := startDatabase(t, dbtest.NewURL(t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import (
|
|||||||
func NewTestDatabase(tb testing.TB) (*Database, error) {
|
func NewTestDatabase(tb testing.TB) (*Database, error) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
dsn := dbtest.NewTestDatabaseURL(tb) + "&_pragma=foreign_keys(1)"
|
dsn := dbtest.NewURL(tb) + "&_pragma=foreign_keys(1)"
|
||||||
|
|
||||||
conn, err := sql.Open("sqlite", dsn)
|
conn, err := sql.Open("sqlite", dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import (
|
|||||||
_ "modernc.org/sqlite" // registers the sqlite driver
|
_ "modernc.org/sqlite" // registers the sqlite driver
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTestDatabaseURL returns the URL of a new, empty in-memory
|
// NewURL returns the URL of a new, empty in-memory database for one
|
||||||
// database for one test. SQLite deletes an in-memory database when
|
// test. SQLite deletes an in-memory database when its last connection
|
||||||
// its last connection closes. A pool closes a connection when a query
|
// closes. A pool closes a connection when a query on it is cancelled
|
||||||
// on it is cancelled while it runs. So this function holds a
|
// while it runs. So this function holds a connection of its own open
|
||||||
// connection of its own open until the test ends.
|
// until the test ends.
|
||||||
func NewTestDatabaseURL(tb testing.TB) string {
|
func NewURL(tb testing.TB) string {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
// A random name, so that no other test can share the database.
|
// A random name, so that no other test can share the database.
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ func newTestServerWith(
|
|||||||
viperMu.Lock()
|
viperMu.Lock()
|
||||||
defer viperMu.Unlock()
|
defer viperMu.Unlock()
|
||||||
|
|
||||||
dbURL := dbtest.NewTestDatabaseURL(t)
|
dbURL := dbtest.NewURL(t)
|
||||||
copyTemplateDB(t, dbURL)
|
copyTemplateDB(t, dbURL)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ func newTestEnvWithResolver(
|
|||||||
) *testEnv {
|
) *testEnv {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
conn, err := sql.Open("sqlite", dbtest.NewTestDatabaseURL(t))
|
conn, err := sql.Open("sqlite", dbtest.NewURL(t))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("open db: %v", err)
|
t.Fatalf("open db: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ func newApp(
|
|||||||
stats.New,
|
stats.New,
|
||||||
),
|
),
|
||||||
fx.Decorate(func(cfg *config.Config) *config.Config {
|
fx.Decorate(func(cfg *config.Config) *config.Config {
|
||||||
cfg.DBURL = dbtest.NewTestDatabaseURL(t)
|
cfg.DBURL = dbtest.NewURL(t)
|
||||||
cfg.Port = port
|
cfg.Port = port
|
||||||
|
|
||||||
return cfg
|
return cfg
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ type testEnv struct {
|
|||||||
func newTestEnv(t *testing.T) *testEnv {
|
func newTestEnv(t *testing.T) *testEnv {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
dbURL := dbtest.NewTestDatabaseURL(t)
|
dbURL := dbtest.NewURL(t)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
database *db.Database
|
database *db.Database
|
||||||
|
|||||||
Reference in new issue
Block a user