Skip to content

Commit 99a81f7

Browse files
t0yv0VenelinMartinov
authored andcommitted
Add a test for DynamicPseudoType reproducing the error
1 parent 359fcbe commit 99a81f7

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

pkg/pf/tests/upgrade_state_cross_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,62 @@ func TestPFUpgrade_Downgrading(t *testing.T) {
10921092
})
10931093
}
10941094

1095+
// Test when a dynamic pseudo type value is being sent through a state upgrader.
1096+
func TestPFUpgrade_DynamicPseudoType(t *testing.T) {
1097+
t.Parallel()
1098+
ct.SkipUnlessLinux(t)
1099+
//skipUnlessDeltasEnabled(t)
1100+
1101+
resourceBefore := pb.NewResource(pb.NewResourceArgs{
1102+
ResourceSchema: schema.Schema{
1103+
Attributes: map[string]schema.Attribute{
1104+
"dyn": schema.DynamicAttribute{Optional: true},
1105+
},
1106+
},
1107+
})
1108+
1109+
resourceAfter := pb.NewResource(pb.NewResourceArgs{
1110+
UpgradeStateFunc: func(ctx context.Context) map[int64]resource.StateUpgrader {
1111+
return map[int64]resource.StateUpgrader{
1112+
0: {
1113+
PriorSchema: &resourceBefore.ResourceSchema,
1114+
StateUpgrader: ct.NopUpgrader,
1115+
},
1116+
}
1117+
},
1118+
ResourceSchema: schema.Schema{
1119+
Attributes: map[string]schema.Attribute{
1120+
"dyn": schema.DynamicAttribute{Optional: true},
1121+
},
1122+
Version: 1,
1123+
},
1124+
})
1125+
1126+
tfInputsBefore := cty.ObjectVal(map[string]cty.Value{"dyn": cty.StringVal("str")})
1127+
tfInputsAfter := cty.ObjectVal(map[string]cty.Value{"dyn": cty.NumberIntVal(42)})
1128+
pmBefore := presource.NewPropertyMapFromMap(map[string]any{"dyn": "str"})
1129+
pmAfter := presource.NewPropertyMapFromMap(map[string]any{"dyn": 42})
1130+
1131+
testCase := ct.UpgradeStateTestCase{
1132+
Resource1: &resourceBefore,
1133+
Resource2: &resourceAfter,
1134+
Inputs1: tfInputsBefore,
1135+
InputsMap1: pmBefore,
1136+
Inputs2: tfInputsAfter,
1137+
InputsMap2: pmAfter,
1138+
//ExpectedRawStateType: resourceBeforeAndAfter.ResourceSchema.Type().TerraformType(context.Background()),
1139+
SkipPulumi: "TODO",
1140+
}
1141+
1142+
_ = testCase.Run(t)
1143+
1144+
// autogold.Expect(map[apitype.OpType]int{apitype.OpType("same"): 2}).Equal(t, result.PulumiPreviewResult.ChangeSummary)
1145+
// autogold.Expect(&map[string]int{"same": 2}).Equal(t, result.PulumiUpResult.Summary.ResourceChanges)
1146+
1147+
// autogold.Expect([]ct.UpgradeStateTrace{}).Equal(t, result.PulumiUpgrades)
1148+
// autogold.Expect([]ct.UpgradeStateTrace{}).Equal(t, result.TFUpgrades)
1149+
}
1150+
10951151
func skipUnlessDeltasEnabled(t *testing.T) {
10961152
if d, ok := os.LookupEnv("PULUMI_RAW_STATE_DELTA_ENABLED"); !ok || !cmdutil.IsTruthy(d) {
10971153
t.Skip("This test requires PULUMI_RAW_STATE_DELTA_ENABLED=true environment")

0 commit comments

Comments
 (0)