From 007cb8eab5feae7a38907c170b66e585d0914fcb Mon Sep 17 00:00:00 2001 From: Vitaly Antonenko Date: Mon, 24 Jun 2024 23:01:25 +0300 Subject: [PATCH] fix: acceptance tests --- internal/provider/modifer_storageset.go | 6 +++-- internal/provider/resource_application.go | 2 +- .../provider/resource_application_test.go | 23 +++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/internal/provider/modifer_storageset.go b/internal/provider/modifer_storageset.go index d41d86c2..5e5d3d2d 100644 --- a/internal/provider/modifer_storageset.go +++ b/internal/provider/modifer_storageset.go @@ -35,7 +35,7 @@ func storageSetRequiresReplace(ctx context.Context, req planmodifier.SetRequest, // Validate storage size parsedStorageSize, err := utils.ParseSize(storageSize) if err != nil { - resp.Diagnostics.AddError("Invalid Storage Size", fmt.Sprintf("Invalid storage size %q: %s", storageSize, err)) + resp.Diagnostics.AddError("1Invalid Storage Size", fmt.Sprintf("1Invalid storage size %q: %s", storageSize, err)) return } @@ -49,6 +49,8 @@ func storageSetRequiresReplace(ctx context.Context, req planmodifier.SetRequest, } stateSet := make(map[string]jujustorage.Constraints) + + // print the state stateSet if !req.StateValue.IsNull() { var stateStorageSlice []nestedStorage resp.Diagnostics.Append(req.StateValue.ElementsAs(ctx, &stateStorageSlice, false)...) @@ -65,7 +67,7 @@ func storageSetRequiresReplace(ctx context.Context, req planmodifier.SetRequest, // Validate storage size parsedStorageSize, err := utils.ParseSize(storageSize) if err != nil { - resp.Diagnostics.AddError("Invalid Storage Size", fmt.Sprintf("Invalid storage size %q: %s", storageSize, err)) + resp.Diagnostics.AddError("2Invalid Storage Size", fmt.Sprintf("2Invalid storage size %q [%q]: %s", storageSize, stateStorageSlice, err)) return } diff --git a/internal/provider/resource_application.go b/internal/provider/resource_application.go index abeee4d4..b2296e93 100644 --- a/internal/provider/resource_application.go +++ b/internal/provider/resource_application.go @@ -554,7 +554,7 @@ func (r *applicationResource) Create(ctx context.Context, req resource.CreateReq // Validate storage size parsedStorageSize, err := utils.ParseSize(storageSize) if err != nil { - resp.Diagnostics.AddError("Invalid Storage Size", fmt.Sprintf("Invalid storage size %q: %s", storageSize, err)) + resp.Diagnostics.AddError("3Invalid Storage Size", fmt.Sprintf("3Invalid storage size %q: %s", storageSize, err)) return } diff --git a/internal/provider/resource_application_test.go b/internal/provider/resource_application_test.go index 7daf51e2..aa3241b1 100644 --- a/internal/provider/resource_application_test.go +++ b/internal/provider/resource_application_test.go @@ -511,7 +511,7 @@ func TestAcc_ResourceApplication_Storage(t *testing.T) { modelName := acctest.RandomWithPrefix("tf-test-application-storage") appName := "test-app-storage" - storageConstraints := map[string]string{"label": "pgdata", "size": "8M", "pool": "lxd", "count": "1"} + storageConstraints := map[string]string{"label": "files", "size": "102M"} resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -522,7 +522,7 @@ func TestAcc_ResourceApplication_Storage(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("juju_application."+appName, "model", modelName), resource.TestCheckResourceAttr("juju_application."+appName, "storage.#", "1"), - resource.TestCheckTypeSetElemNestedAttrs("juju_application."+appName, "storage.*", map[string]string{"pool": "lxd", "size": "8M", "count": "1", "label": "pgdata"}), + resource.TestCheckTypeSetElemNestedAttrs("juju_application."+appName, "storage.*", map[string]string{"size": "102M", "label": "files"}), ), }, { @@ -607,17 +607,21 @@ resource "juju_application" "{{.AppName}}" { channel = "latest/edge" } - {{ if ne .ConfigParamName "" }} + {{- if ne .ConfigParamName "" }} config = { {{.ConfigParamName}} = "{{.ConfigParamName}}-value" } - {{ end }} + storage = [{ + label = "runner" + size = "107G" + }] + {{- end }} - {{ if ne .ResourceParamName "" }} + {{- if ne .ResourceParamName "" }} resources = { {{.ResourceParamName}} = {{.ResourceParamRevision}} } - {{ end }} + {{- end }} units = 1 } @@ -891,16 +895,17 @@ resource "juju_application" "{{.AppName}}" { model = juju_model.{{.ModelName}}.name name = "{{.AppName}}" charm { - name = "postgresql" + name = "ubuntu" + channel = "latest/stable" revision = 24 } storage = [{ label = "{{.StorageConstraints.label}}" size = "{{.StorageConstraints.size}}" - pool = "{{.StorageConstraints.pool}}" - count = {{.StorageConstraints.count}} }] + + units = 1 } `, internaltesting.TemplateData{ "ModelName": modelName,