Skip to content

Commit

Permalink
test with a real database
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed Dec 28, 2024
1 parent 5af7aa9 commit 7f71972
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ import (
type Beeps struct{}

// Start a postgres server
func (m *Beeps) Postgres(init *dagger.File) *dagger.Container {
func (m *Beeps) Postgres() *dagger.Container {
return dag.Postgres(
dag.SetSecret("postgres-user", "beeps"),
dag.SetSecret("postgres-password", "beeps"),
dagger.PostgresOpts{
DbPort: 5432,
DbName: "beeps",
Cache: true,
InitScript: dag.Directory().WithFile("init.sql", init),
DbPort: 5432,
DbName: "beeps",
Cache: true,
},
).Database()
}
Expand Down Expand Up @@ -192,7 +191,14 @@ func (m *Beeps) Test(
source *dagger.Directory,
) *dagger.Container {
return m.rustBase("test").
// Database
WithServiceBinding("postgres", m.Postgres().AsService()).
WithEnvVariable("DATABASE_URL", "postgres://beeps:beeps@postgres:5432/beeps").
WithExec([]string{"cargo", "install", "sqlx-cli", "--no-default-features", "--features=postgres"}).

// Test
With(userSource(source)).
WithExec([]string{"sqlx", "migrate", "run", "--source", "beeps-server/migrations"}).
WithExec([]string{"cargo", "test"})
}

Expand Down

0 comments on commit 7f71972

Please sign in to comment.