Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: DB - Add mount to place test databases in unique folder#91

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletioncoderd/coderdtest/coderdtest.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -63,7 +63,7 @@ func New(t *testing.T) Server {
// This can be hotswapped for a live database instance.
db := databasefake.New()
if os.Getenv("DB") != "" {
connectionURL, close, err := postgres.Open()
connectionURL, close, err := postgres.Open(t.TempDir())
require.NoError(t, err)
t.Cleanup(close)
sqlDB, err := sql.Open("postgres", connectionURL)
Expand Down
2 changes: 1 addition & 1 deletiondatabase/dump/main.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,7 +15,7 @@ import (
)

func main() {
connection, closeFn, err := postgres.Open()
connection, closeFn, err := postgres.Open("")
if err != nil {
panic(err)
}
Expand Down
4 changes: 2 additions & 2 deletionsdatabase/migrate_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,7 @@ func TestMigrate(t *testing.T) {

t.Run("Once", func(t *testing.T) {
t.Parallel()
connection, closeFn, err := postgres.Open()
connection, closeFn, err := postgres.Open(t.TempDir())
require.NoError(t, err)
defer closeFn()
db, err := sql.Open("postgres", connection)
Expand All@@ -34,7 +34,7 @@ func TestMigrate(t *testing.T) {

t.Run("Twice", func(t *testing.T) {
t.Parallel()
connection, closeFn, err := postgres.Open()
connection, closeFn, err := postgres.Open(t.TempDir())
require.NoError(t, err)
defer closeFn()
db, err := sql.Open("postgres", connection)
Expand Down
16 changes: 15 additions & 1 deletiondatabase/postgres/postgres.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,11 +11,24 @@ import (
)

// Open creates a new PostgreSQL server using a Docker container.
func Open() (string, func(), error) {
func Open(databaseDirectory string) (string, func(), error) {
pool, err := dockertest.NewPool("")
if err != nil {
return "", nil, xerrors.Errorf("create pool: %w", err)
}

if err != nil {
return "", nil, xerrors.Errorf("Unable to create temp directory: %w", err)
}

mounts := []string{}
// If databaseDirectory is not specified, we'll just use the default bind path.
// Otherwise, this overrides the volume where postgresql puts its database
// This is important for tests, because we don't want all the tests to put their data in the same place!
if databaseDirectory != "" {
mounts = []string{databaseDirectory + ":/var/lib/postgresql/data"}
}

resource, err := pool.RunWithOptions(&dockertest.RunOptions{
Repository: "postgres",
Tag: "11",
Expand All@@ -25,6 +38,7 @@ func Open() (string, func(), error) {
"POSTGRES_DB=postgres",
"listen_addresses = '*'",
},
Mounts: mounts,
}, func(config *docker.HostConfig) {
// set AutoRemove to true so that stopped container goes away by itself
config.AutoRemove = true
Expand Down
2 changes: 1 addition & 1 deletiondatabase/postgres/postgres_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
func TestPostgres(t *testing.T) {
t.Parallel()

connect, close, err := postgres.Open()
connect, close, err := postgres.Open(t.TempDir())
require.NoError(t, err)
defer close()
db, err := sql.Open("postgres", connect)
Expand Down
2 changes: 1 addition & 1 deletiondatabase/pubsub_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -51,7 +51,7 @@ func TestPubsub(t *testing.T) {
t.Parallel()
ctx, cancelFunc := context.WithCancel(context.Background())
defer cancelFunc()
connectionURL, close, err := postgres.Open()
connectionURL, close, err := postgres.Open(t.TempDir())
require.NoError(t, err)
defer close()
db, err := sql.Open("postgres", connectionURL)
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp