Skip to content

Commit

Permalink
fix: acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anvial committed Jun 24, 2024
1 parent 648a421 commit 007cb8e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
6 changes: 4 additions & 2 deletions internal/provider/modifer_storageset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)...)
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 14 additions & 9 deletions internal/provider/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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"}),
),
},
{
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 007cb8e

Please sign in to comment.