Skip to content

Commit

Permalink
migration: handle unknown dir in validate config (#91)
Browse files Browse the repository at this point in the history
* migration: handle unknown dir in validate config

* chore: fixed test output

* chore: fixed broken tests
  • Loading branch information
giautm authored Nov 5, 2023
1 parent b23df8f commit d0bb46c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/provider/atlas_migration_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,6 @@ func writeDir(t *testing.T, dir migrate.Dir, w io.Writer) {
// Archive and send.
arc, err := migrate.ArchiveDir(dir)
require.NoError(t, err)
_, err = fmt.Fprintf(w, `{"data":{"dir":{"content":%q}}}`, base64.StdEncoding.EncodeToString(arc))
_, err = fmt.Fprintf(w, `{"data":{"dirState":{"content":%q}}}`, base64.StdEncoding.EncodeToString(arc))
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion internal/provider/atlas_migration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func (r MigrationResource) ValidateConfig(ctx context.Context, req resource.Vali
"dir is required when remote_dir is unset",
)
return
case len(data.DirURL.ValueString()) == 0:
case !data.DirURL.IsUnknown() && data.DirURL.ValueString() == "":
resp.Diagnostics.AddError(
"dir is empty",
"dir is required when remote_dir is unset",
Expand Down
7 changes: 5 additions & 2 deletions internal/provider/atlas_migration_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,18 @@ func TestAccMigrationResource(t *testing.T) {
Steps: []resource.TestStep{
{
Config: fmt.Sprintf(`
resource "foo_mirror" "dir" {
value = "migrations"
}
resource "foo_mirror" "schema" {
value = "%s"
}
data "atlas_migration" "hello" {
dir = "migrations?format=atlas"
dir = "${foo_mirror.dir.result}?format=atlas"
url = format("%s/%%s", foo_mirror.schema.result)
}
resource "atlas_migration" "testdb" {
dir = "migrations?format=atlas"
dir = "${foo_mirror.dir.result}?format=atlas"
version = data.atlas_migration.hello.latest
url = data.atlas_migration.hello.url
}`, schema3, mysqlURL),
Expand Down
5 changes: 4 additions & 1 deletion internal/provider/atlas_schema_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,10 @@ table "orders" {
"",
"",
"CREATE DATABASE `test`",
"CREATE TABLE `test`.`orders` (`id` int NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`)) CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci",
"CREATE TABLE `test`.`orders` (",
" `id` int NOT NULL AUTO_INCREMENT,",
" PRIMARY KEY (`id`)",
") CHARSET utf8mb4 COLLATE utf8mb4_0900_ai_ci",
"",
}, "\n")),
},
Expand Down

0 comments on commit d0bb46c

Please sign in to comment.