Skip to content

Commit 8a7b6e8

Browse files
authored
Merge pull request #442 from lxc/fix-zfs-config
Change storage pool config test to use storage_test package
2 parents 8c7f646 + 19cc525 commit 8a7b6e8

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

internal/storage/resource_storage_pool.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func (r *StoragePoolResource) ModifyPlan(ctx context.Context, req resource.Modif
149149
return
150150
}
151151

152-
if plan.Driver.ValueString() == "zfs" && configValueChanged(ctx, state.Config, plan.Config, "source") {
152+
if plan.Driver.ValueString() == "zfs" && ConfigValueChanged(ctx, state.Config, plan.Config, "source") {
153153
resp.RequiresReplace = append(resp.RequiresReplace, path.Root("config").AtMapKey("source"))
154154
}
155155
}
@@ -451,7 +451,8 @@ func preserveUserConfigKeys(driver string) []string {
451451
return nil
452452
}
453453

454-
func configValueChanged(ctx context.Context, stateConfig types.Map, planConfig types.Map, key string) bool {
454+
// ConfigValueChanged returns true if the state or plan config values for the given key are different.
455+
func ConfigValueChanged(ctx context.Context, stateConfig types.Map, planConfig types.Map, key string) bool {
455456
stateValue, stateOK := configValue(ctx, stateConfig, key)
456457
planValue, planOK := configValue(ctx, planConfig, key)
457458

internal/storage/resource_storage_pool_config_test.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
package storage
1+
package storage_test
22

33
import (
44
"context"
55
"testing"
66

77
"github.com/hashicorp/terraform-plugin-framework/attr"
88
"github.com/hashicorp/terraform-plugin-framework/types"
9+
10+
"github.com/lxc/terraform-provider-incus/internal/storage"
911
)
1012

1113
func TestStoragePoolPreserveUserConfig_Source(t *testing.T) {
1214
userSource := "/dev/disk/by-id/test-disk"
1315
apiSource := "pool1"
1416

15-
model := StoragePoolModel{
17+
model := storage.StoragePoolModel{
1618
Config: types.MapValueMust(types.StringType, map[string]attr.Value{
1719
"source": types.StringValue(userSource),
1820
}),
@@ -37,7 +39,7 @@ func TestStoragePoolPreserveUserConfig_NonZFSDriver(t *testing.T) {
3739
userSource := "/dev/disk/by-id/test-disk"
3840
apiSource := "pool1"
3941

40-
model := StoragePoolModel{
42+
model := storage.StoragePoolModel{
4143
Config: types.MapValueMust(types.StringType, map[string]attr.Value{
4244
"source": types.StringValue(userSource),
4345
}),
@@ -69,7 +71,7 @@ func TestStoragePoolConfigValueChanged(t *testing.T) {
6971
"source": types.StringValue("/dev/disk/by-id/disk-b"),
7072
})
7173

72-
if !configValueChanged(ctx, stateConfig, planConfig, "source") {
74+
if !storage.ConfigValueChanged(ctx, stateConfig, planConfig, "source") {
7375
t.Fatal("expected source change to be detected")
7476
}
7577
}
@@ -85,7 +87,7 @@ func TestStoragePoolConfigValueChanged_Unchanged(t *testing.T) {
8587
"source": types.StringValue("/dev/disk/by-id/disk-a"),
8688
})
8789

88-
if configValueChanged(ctx, stateConfig, planConfig, "source") {
90+
if storage.ConfigValueChanged(ctx, stateConfig, planConfig, "source") {
8991
t.Fatal("expected unchanged source not to be detected as changed")
9092
}
9193
}

0 commit comments

Comments
 (0)