@@ -2553,6 +2553,111 @@ func TestRelevantAttributes(t *testing.T) {
25532553 }
25542554}
25552555
2556+ func TestDynamicPseudoType (t * testing.T ) {
2557+ tcs := map [string ]struct {
2558+ input structured.Change
2559+ validate renderers.ValidateDiffFunction
2560+ }{
2561+ "after_sensitive_in_dynamic_type" : {
2562+ input : structured.Change {
2563+ Before : nil ,
2564+ After : map [string ]interface {}{
2565+ "key" : "value" ,
2566+ },
2567+ Unknown : false ,
2568+ BeforeSensitive : false ,
2569+ AfterSensitive : map [string ]interface {}{
2570+ "key" : true ,
2571+ },
2572+ ReplacePaths : attribute_path .Empty (false ),
2573+ RelevantAttributes : attribute_path .AlwaysMatcher (),
2574+ },
2575+ validate : renderers .ValidateObject (map [string ]renderers.ValidateDiffFunction {
2576+ "key" : renderers .ValidateSensitive (renderers .ValidatePrimitive (nil , "value" , plans .Create , false ), false , true , plans .Create , false ),
2577+ }, plans .Create , false ),
2578+ },
2579+ "before_sensitive_in_dynamic_type" : {
2580+ input : structured.Change {
2581+ Before : map [string ]interface {}{
2582+ "key" : "value" ,
2583+ },
2584+ After : nil ,
2585+ Unknown : false ,
2586+ BeforeSensitive : map [string ]interface {}{
2587+ "key" : true ,
2588+ },
2589+ AfterSensitive : false ,
2590+ ReplacePaths : attribute_path .Empty (false ),
2591+ RelevantAttributes : attribute_path .AlwaysMatcher (),
2592+ },
2593+ validate : renderers .ValidateObject (map [string ]renderers.ValidateDiffFunction {
2594+ "key" : renderers .ValidateSensitive (renderers .ValidatePrimitive ("value" , nil , plans .Delete , false ), true , false , plans .Delete , false ),
2595+ }, plans .Delete , false ),
2596+ },
2597+ "sensitive_in_dynamic_type" : {
2598+ input : structured.Change {
2599+ Before : map [string ]interface {}{
2600+ "key" : "before" ,
2601+ },
2602+ After : map [string ]interface {}{
2603+ "key" : "after" ,
2604+ },
2605+ Unknown : false ,
2606+ BeforeSensitive : map [string ]interface {}{
2607+ "key" : true ,
2608+ },
2609+ AfterSensitive : map [string ]interface {}{
2610+ "key" : true ,
2611+ },
2612+ ReplacePaths : attribute_path .Empty (false ),
2613+ RelevantAttributes : attribute_path .AlwaysMatcher (),
2614+ },
2615+ validate : renderers .ValidateObject (map [string ]renderers.ValidateDiffFunction {
2616+ "key" : renderers .ValidateSensitive (renderers .ValidatePrimitive ("before" , "after" , plans .Update , false ), true , true , plans .Update , false ),
2617+ }, plans .Update , false ),
2618+ },
2619+ "create_unknown_in_dynamic_type" : {
2620+ input : structured.Change {
2621+ Before : nil ,
2622+ After : map [string ]interface {}{},
2623+ Unknown : map [string ]interface {}{
2624+ "key" : true ,
2625+ },
2626+ BeforeSensitive : false ,
2627+ AfterSensitive : false ,
2628+ ReplacePaths : attribute_path .Empty (false ),
2629+ RelevantAttributes : attribute_path .AlwaysMatcher (),
2630+ },
2631+ validate : renderers .ValidateObject (map [string ]renderers.ValidateDiffFunction {
2632+ "key" : renderers .ValidateUnknown (nil , plans .Create , false ),
2633+ }, plans .Create , false ),
2634+ },
2635+ "update_unknown_in_dynamic_type" : {
2636+ input : structured.Change {
2637+ Before : map [string ]interface {}{
2638+ "key" : "before" ,
2639+ },
2640+ After : map [string ]interface {}{},
2641+ Unknown : map [string ]interface {}{
2642+ "key" : true ,
2643+ },
2644+ BeforeSensitive : false ,
2645+ AfterSensitive : false ,
2646+ ReplacePaths : attribute_path .Empty (false ),
2647+ RelevantAttributes : attribute_path .AlwaysMatcher (),
2648+ },
2649+ validate : renderers .ValidateObject (map [string ]renderers.ValidateDiffFunction {
2650+ "key" : renderers .ValidateUnknown (renderers .ValidatePrimitive ("before" , nil , plans .Delete , false ), plans .Update , false ),
2651+ }, plans .Update , false ),
2652+ },
2653+ }
2654+ for key , tc := range tcs {
2655+ t .Run (key , func (t * testing.T ) {
2656+ tc .validate (t , ComputeDiffForType (tc .input , cty .DynamicPseudoType ))
2657+ })
2658+ }
2659+ }
2660+
25562661func TestSpecificCases (t * testing.T ) {
25572662 // This is a special test that can contain any combination of individual
25582663 // cases and will execute against them. For testing/fixing specific issues
0 commit comments