Skip to content

feat(analyzer): Automatically create databases #3376

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try and use auto for tests
  • Loading branch information
kyleconroy committed May 10, 2024
commit fda2e458c3d38978f9f1400b52557db5a3892c5c
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ install:
test:
go test ./...

test-managed:
MYSQL_SERVER_URI="invalid" POSTGRESQL_SERVER_URI="postgres://postgres:mysecretpassword@localhost:5432/postgres" go test ./...

vet:
go vet ./...

Expand Down
21 changes: 13 additions & 8 deletions internal/endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,26 @@ func TestReplay(t *testing.T) {
"managed-db": {
Mutate: func(t *testing.T, path string) func(*config.Config) {
return func(c *config.Config) {
c.Servers = []config.Server{
{
Name: "postgres",
URI: local.PostgreSQLServer(),
},

{
Name: "mysql",
URI: local.MySQLServer(),
},
}
for i := range c.SQL {
files := []string{}
for _, s := range c.SQL[i].Schema {
files = append(files, filepath.Join(path, s))
}
switch c.SQL[i].Engine {
case config.EnginePostgreSQL:
uri := local.ReadOnlyPostgreSQL(t, files)
c.SQL[i].Database = &config.Database{
URI: uri,
Auto: true,
}
case config.EngineMySQL:
uri := local.MySQL(t, files)
c.SQL[i].Database = &config.Database{
URI: uri,
Auto: true,
}
default:
// pass
Expand Down
4 changes: 4 additions & 0 deletions internal/sqltest/local/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
var mysqlSync sync.Once
var mysqlPool *sql.DB

func MySQLServer() string {
return os.Getenv("MYSQL_SERVER_URI")
}

func MySQL(t *testing.T, migrations []string) string {
ctx := context.Background()
t.Helper()
Expand Down
4 changes: 4 additions & 0 deletions internal/sqltest/local/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func ReadOnlyPostgreSQL(t *testing.T, migrations []string) string {
return postgreSQL(t, migrations, false)
}

func PostgreSQLServer() string {
return os.Getenv("POSTGRESQL_SERVER_URI")
}

func postgreSQL(t *testing.T, migrations []string, rw bool) string {
ctx := context.Background()
t.Helper()
Expand Down