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