Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao committed Jan 8, 2025
1 parent 8367351 commit 1ffd11b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/controller/atlasschema_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
return err
})
}
if !data.hasDevURL() && data.URL != nil {
// The user has not specified an URL for dev-db,
// spin up a dev-db and get the connection string.
data.DevURL, err = r.devDB.devURL(ctx, res, *data.URL)
if err != nil {
res.SetNotReady("GettingDevDB", err.Error())
return result(err)
}
}
// Create a working directory for the Atlas CLI
// The working directory contains the atlas.hcl config.
wd, err := atlasexec.NewWorkingDir(opts...)
Expand Down Expand Up @@ -174,6 +183,7 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// Calculate the hash of the current schema.
hash, err := cli.SchemaInspect(ctx, &atlasexec.SchemaInspectParams{
Env: data.EnvName,
URL: "env://schema.src",
Format: `{{ .Hash | base64url }}`,
Vars: data.Vars,
})
Expand All @@ -193,15 +203,6 @@ func (r *AtlasSchemaReconciler) Reconcile(ctx context.Context, req ctrl.Request)
// Starting area to handle the heavy jobs.
// Below this line is the main logic of the controller.
// ====================================================
if !data.hasDevURL() && data.URL != nil {
// The user has not specified an URL for dev-db,
// spin up a dev-db and get the connection string.
data.DevURL, err = r.devDB.devURL(ctx, res, *data.URL)
if err != nil {
res.SetNotReady("GettingDevDB", err.Error())
return result(err)
}
}
var whoami *atlasexec.WhoAmI
switch whoami, err = cli.WhoAmI(ctx); {
case errors.Is(err, atlasexec.ErrRequireLogin):
Expand Down
9 changes: 9 additions & 0 deletions internal/controller/atlasschema_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ func TestConfigTemplate(t *testing.T) {
err := data.render(&buf)
require.NoError(t, err)
expected := `env "kubernetes" {
schema {
src = "file://schema.sql"
}
url = "mysql://root:password@localhost:3306/test"
dev = "mysql://root:password@localhost:3306/dev"
schemas = ["foo", "bar"]
Expand Down Expand Up @@ -573,6 +576,9 @@ env "kubernetes" {
dev = "mysql://root:password@localhost:3306/dev"
schemas = ["foo", "bar"]
url = "mysql://root:password@localhost:3306/test"
schema {
src = "file://schema.sql"
}
}
`
require.EqualValues(t, expected, buf.String())
Expand All @@ -599,6 +605,9 @@ env {
dev = "mysql://root:password@localhost:3306/dev"
schemas = ["foo", "bar"]
url = "mysql://root:password@localhost:3306/test"
schema {
src = "file://schema.sql"
}
}`
require.EqualValues(t, expected, buf.String())
}
Expand Down

0 comments on commit 1ffd11b

Please sign in to comment.