Skip to content

Commit 4277894

Browse files
committed
Add 'deeply nested set' test
1 parent 92a01c1 commit 4277894

File tree

1 file changed

+319
-0
lines changed

1 file changed

+319
-0
lines changed

internal/fwserver/schema_propose_new_plan_test.go

Lines changed: 319 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,325 @@ func TestSchemaProposeNewState(t *testing.T) {
28222822
}),
28232823
},
28242824
},
2825+
"deeply nested set": {
2826+
schema: schema.Schema{
2827+
Attributes: map[string]schema.Attribute{
2828+
"set_nested_attribute": schema.SetNestedAttribute{
2829+
Optional: true,
2830+
NestedObject: schema.NestedAttributeObject{
2831+
Attributes: map[string]schema.Attribute{
2832+
"nested_set_nested_attribute": schema.SetNestedAttribute{
2833+
NestedObject: schema.NestedAttributeObject{
2834+
Attributes: testAttributes,
2835+
},
2836+
Required: true,
2837+
},
2838+
},
2839+
},
2840+
},
2841+
},
2842+
},
2843+
priorVal: map[string]tftypes.Value{
2844+
"set_nested_attribute": tftypes.NewValue(
2845+
tftypes.Set{
2846+
ElementType: tftypes.Object{
2847+
AttributeTypes: map[string]tftypes.Type{
2848+
"nested_set_nested_attribute": tftypes.Set{
2849+
ElementType: tftypes.Object{
2850+
AttributeTypes: map[string]tftypes.Type{
2851+
"optional": tftypes.String,
2852+
"computed": tftypes.String,
2853+
"optional_computed": tftypes.String,
2854+
"required": tftypes.String,
2855+
},
2856+
},
2857+
},
2858+
},
2859+
},
2860+
},
2861+
[]tftypes.Value{
2862+
tftypes.NewValue(tftypes.Object{
2863+
AttributeTypes: map[string]tftypes.Type{
2864+
"nested_set_nested_attribute": tftypes.Set{
2865+
ElementType: tftypes.Object{
2866+
AttributeTypes: map[string]tftypes.Type{
2867+
"optional": tftypes.String,
2868+
"computed": tftypes.String,
2869+
"optional_computed": tftypes.String,
2870+
"required": tftypes.String,
2871+
},
2872+
},
2873+
},
2874+
},
2875+
}, map[string]tftypes.Value{
2876+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
2877+
ElementType: tftypes.Object{
2878+
AttributeTypes: map[string]tftypes.Type{
2879+
"optional": tftypes.String,
2880+
"computed": tftypes.String,
2881+
"optional_computed": tftypes.String,
2882+
"required": tftypes.String,
2883+
},
2884+
},
2885+
}, []tftypes.Value{
2886+
tftypes.NewValue(tftypes.Object{
2887+
AttributeTypes: map[string]tftypes.Type{
2888+
"optional": tftypes.String,
2889+
"computed": tftypes.String,
2890+
"optional_computed": tftypes.String,
2891+
"required": tftypes.String,
2892+
},
2893+
}, map[string]tftypes.Value{
2894+
"optional": tftypes.NewValue(tftypes.String, "prior"),
2895+
"computed": tftypes.NewValue(tftypes.String, "prior"),
2896+
"optional_computed": tftypes.NewValue(tftypes.String, "prior"),
2897+
"required": tftypes.NewValue(tftypes.String, "prior"),
2898+
}),
2899+
}),
2900+
}),
2901+
tftypes.NewValue(tftypes.Object{
2902+
AttributeTypes: map[string]tftypes.Type{
2903+
"nested_set_nested_attribute": tftypes.Set{
2904+
ElementType: tftypes.Object{
2905+
AttributeTypes: map[string]tftypes.Type{
2906+
"optional": tftypes.String,
2907+
"computed": tftypes.String,
2908+
"optional_computed": tftypes.String,
2909+
"required": tftypes.String,
2910+
},
2911+
},
2912+
},
2913+
},
2914+
}, map[string]tftypes.Value{
2915+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
2916+
ElementType: tftypes.Object{
2917+
AttributeTypes: map[string]tftypes.Type{
2918+
"optional": tftypes.String,
2919+
"computed": tftypes.String,
2920+
"optional_computed": tftypes.String,
2921+
"required": tftypes.String,
2922+
},
2923+
},
2924+
}, []tftypes.Value{
2925+
tftypes.NewValue(tftypes.Object{
2926+
AttributeTypes: map[string]tftypes.Type{
2927+
"optional": tftypes.String,
2928+
"computed": tftypes.String,
2929+
"optional_computed": tftypes.String,
2930+
"required": tftypes.String,
2931+
},
2932+
}, map[string]tftypes.Value{
2933+
"optional": tftypes.NewValue(tftypes.String, "other_prior"),
2934+
"computed": tftypes.NewValue(tftypes.String, "other_prior"),
2935+
"optional_computed": tftypes.NewValue(tftypes.String, "other_prior"),
2936+
"required": tftypes.NewValue(tftypes.String, "other_prior"),
2937+
}),
2938+
}),
2939+
}),
2940+
},
2941+
),
2942+
},
2943+
configVal: map[string]tftypes.Value{
2944+
"set_nested_attribute": tftypes.NewValue(
2945+
tftypes.Set{
2946+
ElementType: tftypes.Object{
2947+
AttributeTypes: map[string]tftypes.Type{
2948+
"nested_set_nested_attribute": tftypes.Set{
2949+
ElementType: tftypes.Object{
2950+
AttributeTypes: map[string]tftypes.Type{
2951+
"optional": tftypes.String,
2952+
"computed": tftypes.String,
2953+
"optional_computed": tftypes.String,
2954+
"required": tftypes.String,
2955+
},
2956+
},
2957+
},
2958+
},
2959+
},
2960+
},
2961+
[]tftypes.Value{
2962+
tftypes.NewValue(tftypes.Object{
2963+
AttributeTypes: map[string]tftypes.Type{
2964+
"nested_set_nested_attribute": tftypes.Set{
2965+
ElementType: tftypes.Object{
2966+
AttributeTypes: map[string]tftypes.Type{
2967+
"optional": tftypes.String,
2968+
"computed": tftypes.String,
2969+
"optional_computed": tftypes.String,
2970+
"required": tftypes.String,
2971+
},
2972+
},
2973+
},
2974+
},
2975+
}, map[string]tftypes.Value{
2976+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
2977+
ElementType: tftypes.Object{
2978+
AttributeTypes: map[string]tftypes.Type{
2979+
"optional": tftypes.String,
2980+
"computed": tftypes.String,
2981+
"optional_computed": tftypes.String,
2982+
"required": tftypes.String,
2983+
},
2984+
},
2985+
}, []tftypes.Value{
2986+
tftypes.NewValue(tftypes.Object{
2987+
AttributeTypes: map[string]tftypes.Type{
2988+
"optional": tftypes.String,
2989+
"computed": tftypes.String,
2990+
"optional_computed": tftypes.String,
2991+
"required": tftypes.String,
2992+
},
2993+
}, map[string]tftypes.Value{
2994+
"optional": tftypes.NewValue(tftypes.String, "configured"),
2995+
"computed": tftypes.NewValue(tftypes.String, nil), // computed attrs are null in config
2996+
"optional_computed": tftypes.NewValue(tftypes.String, "configured"),
2997+
"required": tftypes.NewValue(tftypes.String, "configured"),
2998+
}),
2999+
}),
3000+
}),
3001+
tftypes.NewValue(tftypes.Object{
3002+
AttributeTypes: map[string]tftypes.Type{
3003+
"nested_set_nested_attribute": tftypes.Set{
3004+
ElementType: tftypes.Object{
3005+
AttributeTypes: map[string]tftypes.Type{
3006+
"optional": tftypes.String,
3007+
"computed": tftypes.String,
3008+
"optional_computed": tftypes.String,
3009+
"required": tftypes.String,
3010+
},
3011+
},
3012+
},
3013+
},
3014+
}, map[string]tftypes.Value{
3015+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
3016+
ElementType: tftypes.Object{
3017+
AttributeTypes: map[string]tftypes.Type{
3018+
"optional": tftypes.String,
3019+
"computed": tftypes.String,
3020+
"optional_computed": tftypes.String,
3021+
"required": tftypes.String,
3022+
},
3023+
},
3024+
}, []tftypes.Value{
3025+
tftypes.NewValue(tftypes.Object{
3026+
AttributeTypes: map[string]tftypes.Type{
3027+
"optional": tftypes.String,
3028+
"computed": tftypes.String,
3029+
"optional_computed": tftypes.String,
3030+
"required": tftypes.String,
3031+
},
3032+
}, map[string]tftypes.Value{
3033+
"optional": tftypes.NewValue(tftypes.String, nil), // explicit null in config
3034+
"computed": tftypes.NewValue(tftypes.String, nil), // computed attrs are null in config
3035+
"optional_computed": tftypes.NewValue(tftypes.String, "other_configured"),
3036+
"required": tftypes.NewValue(tftypes.String, "other_configured"),
3037+
}),
3038+
}),
3039+
}),
3040+
},
3041+
),
3042+
},
3043+
expectedVal: map[string]tftypes.Value{
3044+
"set_nested_attribute": tftypes.NewValue(
3045+
tftypes.Set{
3046+
ElementType: tftypes.Object{
3047+
AttributeTypes: map[string]tftypes.Type{
3048+
"nested_set_nested_attribute": tftypes.Set{
3049+
ElementType: tftypes.Object{
3050+
AttributeTypes: map[string]tftypes.Type{
3051+
"optional": tftypes.String,
3052+
"computed": tftypes.String,
3053+
"optional_computed": tftypes.String,
3054+
"required": tftypes.String,
3055+
},
3056+
},
3057+
},
3058+
},
3059+
},
3060+
},
3061+
[]tftypes.Value{
3062+
tftypes.NewValue(tftypes.Object{
3063+
AttributeTypes: map[string]tftypes.Type{
3064+
"nested_set_nested_attribute": tftypes.Set{
3065+
ElementType: tftypes.Object{
3066+
AttributeTypes: map[string]tftypes.Type{
3067+
"optional": tftypes.String,
3068+
"computed": tftypes.String,
3069+
"optional_computed": tftypes.String,
3070+
"required": tftypes.String,
3071+
},
3072+
},
3073+
},
3074+
},
3075+
}, map[string]tftypes.Value{
3076+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
3077+
ElementType: tftypes.Object{
3078+
AttributeTypes: map[string]tftypes.Type{
3079+
"optional": tftypes.String,
3080+
"computed": tftypes.String,
3081+
"optional_computed": tftypes.String,
3082+
"required": tftypes.String,
3083+
},
3084+
},
3085+
}, []tftypes.Value{
3086+
tftypes.NewValue(tftypes.Object{
3087+
AttributeTypes: map[string]tftypes.Type{
3088+
"optional": tftypes.String,
3089+
"computed": tftypes.String,
3090+
"optional_computed": tftypes.String,
3091+
"required": tftypes.String,
3092+
},
3093+
}, map[string]tftypes.Value{
3094+
"optional": tftypes.NewValue(tftypes.String, "configured"),
3095+
"computed": tftypes.NewValue(tftypes.String, nil),
3096+
"optional_computed": tftypes.NewValue(tftypes.String, "configured"),
3097+
"required": tftypes.NewValue(tftypes.String, "configured"),
3098+
}),
3099+
}),
3100+
}),
3101+
tftypes.NewValue(tftypes.Object{
3102+
AttributeTypes: map[string]tftypes.Type{
3103+
"nested_set_nested_attribute": tftypes.Set{
3104+
ElementType: tftypes.Object{
3105+
AttributeTypes: map[string]tftypes.Type{
3106+
"optional": tftypes.String,
3107+
"computed": tftypes.String,
3108+
"optional_computed": tftypes.String,
3109+
"required": tftypes.String,
3110+
},
3111+
},
3112+
},
3113+
},
3114+
}, map[string]tftypes.Value{
3115+
"nested_set_nested_attribute": tftypes.NewValue(tftypes.Set{
3116+
ElementType: tftypes.Object{
3117+
AttributeTypes: map[string]tftypes.Type{
3118+
"optional": tftypes.String,
3119+
"computed": tftypes.String,
3120+
"optional_computed": tftypes.String,
3121+
"required": tftypes.String,
3122+
},
3123+
},
3124+
}, []tftypes.Value{
3125+
tftypes.NewValue(tftypes.Object{
3126+
AttributeTypes: map[string]tftypes.Type{
3127+
"optional": tftypes.String,
3128+
"computed": tftypes.String,
3129+
"optional_computed": tftypes.String,
3130+
"required": tftypes.String,
3131+
},
3132+
}, map[string]tftypes.Value{
3133+
"optional": tftypes.NewValue(tftypes.String, nil), // explicit null in config is preserved
3134+
"computed": tftypes.NewValue(tftypes.String, nil),
3135+
"optional_computed": tftypes.NewValue(tftypes.String, "other_configured"),
3136+
"required": tftypes.NewValue(tftypes.String, "other_configured"),
3137+
}),
3138+
}),
3139+
}),
3140+
},
3141+
),
3142+
},
3143+
},
28253144
}
28263145

28273146
for name, test := range tests {

0 commit comments

Comments
 (0)