|
1 | 1 | package tfbridgetests |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "math/big" |
5 | 6 | "testing" |
6 | 7 |
|
| 8 | + "github.com/hashicorp/terraform-plugin-framework/resource" |
7 | 9 | rschema "github.com/hashicorp/terraform-plugin-framework/resource/schema" |
8 | 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" |
9 | 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" |
@@ -188,22 +190,96 @@ func TestPFDetailedDiffDynamicType(t *testing.T) { |
188 | 190 | }, |
189 | 191 | }, |
190 | 192 | } |
| 193 | + res := pb.NewResource(pb.NewResourceArgs{ |
| 194 | + ResourceSchema: attributeSchema, |
| 195 | + }) |
191 | 196 |
|
192 | 197 | t.Run("no change", func(t *testing.T) { |
193 | | - crosstests.Diff(t, pb.NewResource(pb.NewResourceArgs{ |
194 | | - ResourceSchema: attributeSchema, |
195 | | - }), map[string]cty.Value{"key": cty.StringVal("value")}, map[string]cty.Value{"key": cty.StringVal("value")}) |
| 198 | + crosstests.Diff(t, res, |
| 199 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 200 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 201 | + ) |
196 | 202 | }) |
197 | 203 |
|
198 | 204 | t.Run("change", func(t *testing.T) { |
199 | | - crosstests.Diff(t, pb.NewResource(pb.NewResourceArgs{ |
200 | | - ResourceSchema: attributeSchema, |
201 | | - }), map[string]cty.Value{"key": cty.StringVal("value")}, map[string]cty.Value{"key": cty.StringVal("value1")}) |
| 205 | + crosstests.Diff(t, res, |
| 206 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 207 | + map[string]cty.Value{"key": cty.StringVal("value1")}, |
| 208 | + ) |
202 | 209 | }) |
203 | 210 |
|
204 | 211 | t.Run("int no change", func(t *testing.T) { |
205 | | - crosstests.Diff(t, pb.NewResource(pb.NewResourceArgs{ |
206 | | - ResourceSchema: attributeSchema, |
207 | | - }), map[string]cty.Value{"key": cty.NumberVal(big.NewFloat(1))}, map[string]cty.Value{"key": cty.NumberVal(big.NewFloat(1))}) |
| 212 | + crosstests.Diff(t, res, |
| 213 | + map[string]cty.Value{"key": cty.NumberVal(big.NewFloat(1))}, |
| 214 | + map[string]cty.Value{"key": cty.NumberVal(big.NewFloat(1))}, |
| 215 | + ) |
| 216 | + }) |
| 217 | + |
| 218 | + t.Run("type change", func(t *testing.T) { |
| 219 | + // TODO[pulumi/pulumi-terraform-bridge#3078] |
| 220 | + t.Skip(`Error converting tftypes.Number<"1"> (value2) at "AttributeName(\"key\")": can't unmarshal tftypes.Number into *string, expected string`) |
| 221 | + crosstests.Diff(t, res, |
| 222 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 223 | + map[string]cty.Value{"key": cty.NumberVal(big.NewFloat(1))}, |
| 224 | + ) |
| 225 | + }) |
| 226 | +} |
| 227 | + |
| 228 | +func TestPFDetailedDiffDynamicTypeWithMigration(t *testing.T) { |
| 229 | + t.Parallel() |
| 230 | + // TODO[pulumi/pulumi-terraform-bridge#3078] |
| 231 | + t.Skip("DynamicPseudoType is not supported") |
| 232 | + |
| 233 | + attributeSchema := rschema.Schema{ |
| 234 | + Attributes: map[string]rschema.Attribute{ |
| 235 | + "key": rschema.DynamicAttribute{ |
| 236 | + Optional: true, |
| 237 | + }, |
| 238 | + }, |
| 239 | + } |
| 240 | + res1 := pb.NewResource(pb.NewResourceArgs{ |
| 241 | + ResourceSchema: attributeSchema, |
| 242 | + }) |
| 243 | + |
| 244 | + schema2 := rschema.Schema{ |
| 245 | + Attributes: map[string]rschema.Attribute{ |
| 246 | + "key": rschema.DynamicAttribute{ |
| 247 | + Optional: true, |
| 248 | + }, |
| 249 | + }, |
| 250 | + Version: 1, |
| 251 | + } |
| 252 | + res2 := pb.NewResource(pb.NewResourceArgs{ |
| 253 | + ResourceSchema: schema2, |
| 254 | + UpgradeStateFunc: func(ctx context.Context) map[int64]resource.StateUpgrader { |
| 255 | + return map[int64]resource.StateUpgrader{ |
| 256 | + 0: { |
| 257 | + PriorSchema: &res1.ResourceSchema, |
| 258 | + StateUpgrader: func(ctx context.Context, usr1 resource.UpgradeStateRequest, usr2 *resource.UpgradeStateResponse) { |
| 259 | + usr2.State = *usr1.State |
| 260 | + }, |
| 261 | + }, |
| 262 | + } |
| 263 | + }, |
| 264 | + }) |
| 265 | + |
| 266 | + t.Run("no change", func(t *testing.T) { |
| 267 | + crosstests.Diff(t, res1, |
| 268 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 269 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 270 | + crosstests.DiffProviderUpgradedSchema( |
| 271 | + res2, |
| 272 | + ), |
| 273 | + ) |
| 274 | + }) |
| 275 | + |
| 276 | + t.Run("change", func(t *testing.T) { |
| 277 | + crosstests.Diff(t, res1, |
| 278 | + map[string]cty.Value{"key": cty.StringVal("value")}, |
| 279 | + map[string]cty.Value{"key": cty.StringVal("value1")}, |
| 280 | + crosstests.DiffProviderUpgradedSchema( |
| 281 | + res2, |
| 282 | + ), |
| 283 | + ) |
208 | 284 | }) |
209 | 285 | } |
0 commit comments