From d0bb46c316fe84161994245f238ca418a26d45dd Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" <12751435+giautm@users.noreply.github.com> Date: Sun, 5 Nov 2023 17:58:51 +0700 Subject: [PATCH] migration: handle unknown dir in validate config (#91) * migration: handle unknown dir in validate config * chore: fixed test output * chore: fixed broken tests --- internal/provider/atlas_migration_data_source_test.go | 2 +- internal/provider/atlas_migration_resource.go | 2 +- internal/provider/atlas_migration_resource_test.go | 7 +++++-- internal/provider/atlas_schema_resource_test.go | 5 ++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/internal/provider/atlas_migration_data_source_test.go b/internal/provider/atlas_migration_data_source_test.go index 69b8a6a..becc59b 100644 --- a/internal/provider/atlas_migration_data_source_test.go +++ b/internal/provider/atlas_migration_data_source_test.go @@ -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) } diff --git a/internal/provider/atlas_migration_resource.go b/internal/provider/atlas_migration_resource.go index 7a7df80..bb505da 100644 --- a/internal/provider/atlas_migration_resource.go +++ b/internal/provider/atlas_migration_resource.go @@ -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", diff --git a/internal/provider/atlas_migration_resource_test.go b/internal/provider/atlas_migration_resource_test.go index 19e7dfe..b784d80 100644 --- a/internal/provider/atlas_migration_resource_test.go +++ b/internal/provider/atlas_migration_resource_test.go @@ -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), diff --git a/internal/provider/atlas_schema_resource_test.go b/internal/provider/atlas_schema_resource_test.go index 70ba919..f84bed8 100644 --- a/internal/provider/atlas_schema_resource_test.go +++ b/internal/provider/atlas_schema_resource_test.go @@ -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")), },