99 "github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
1010)
1111
12- func setScenarios () []diffScenario [[]string ] {
12+ func oneElementScenarios () []diffScenario [[]string ] {
1313 return []diffScenario [[]string ]{
1414 {"unchanged non-empty" , & []string {"value" }, & []string {"value" }},
1515 {"unchanged empty" , & []string {}, & []string {}},
@@ -23,7 +23,12 @@ func setScenarios() []diffScenario[[]string] {
2323
2424 {"added" , & []string {}, & []string {"value" }},
2525 {"removed" , & []string {"value" }, & []string {}},
26+ }
27+ }
2628
29+ func setScenarios () []diffScenario [[]string ] {
30+ scenarios := oneElementScenarios ()
31+ multiElementScenarios := []diffScenario [[]string ]{
2732 {"removed front" , & []string {"val1" , "val2" , "val3" }, & []string {"val2" , "val3" }},
2833 {"removed front unordered" , & []string {"val2" , "val3" , "val1" }, & []string {"val3" , "val1" }},
2934 {"removed middle" , & []string {"val1" , "val2" , "val3" }, & []string {"val1" , "val3" }},
@@ -61,6 +66,8 @@ func setScenarios() []diffScenario[[]string] {
6166 {"two added and two removed shuffled, no overlaps" , & []string {"val1" , "val2" , "val3" , "val4" }, & []string {"val5" , "val6" , "val1" , "val2" }},
6267 {"two added and two removed shuffled, with duplicates" , & []string {"val1" , "val2" , "val3" , "val4" }, & []string {"val1" , "val5" , "val6" , "val2" , "val1" , "val2" }},
6368 }
69+
70+ return append (scenarios , multiElementScenarios ... )
6471}
6572
6673func TestSDKv2DetailedDiffSetAttribute (t * testing.T ) {
@@ -580,3 +587,96 @@ func TestSDKv2DetailedDiffSetDefault(t *testing.T) {
580587
581588 runSDKv2TestMatrix (t , diffSchemaValueMakerPairs , setScenarios ())
582589}
590+
591+ func TestSDKv2DetailedDiffSetMaxItemsOne (t * testing.T ) {
592+ t .Parallel ()
593+
594+ maxItemsOneAttrSchema := schema.Resource {
595+ Schema : map [string ]* schema.Schema {
596+ "prop" : {
597+ Type : schema .TypeSet ,
598+ Optional : true ,
599+ MaxItems : 1 ,
600+ Elem : & schema.Schema {Type : schema .TypeString },
601+ },
602+ },
603+ }
604+
605+ maxItemsOneAttrSchemaForceNew := schema.Resource {
606+ Schema : map [string ]* schema.Schema {
607+ "prop" : {
608+ Type : schema .TypeSet ,
609+ Optional : true ,
610+ ForceNew : true ,
611+ MaxItems : 1 ,
612+ Elem : & schema.Schema {Type : schema .TypeString },
613+ },
614+ },
615+ }
616+
617+ maxItemsOneBlockSchema := schema.Resource {
618+ Schema : map [string ]* schema.Schema {
619+ "prop" : {
620+ Type : schema .TypeSet ,
621+ Optional : true ,
622+ MaxItems : 1 ,
623+ Elem : & schema.Resource {
624+ Schema : map [string ]* schema.Schema {
625+ "nested_prop" : {
626+ Type : schema .TypeString ,
627+ Optional : true ,
628+ },
629+ },
630+ },
631+ },
632+ },
633+ }
634+
635+ maxItemsOneBlockSchemaForceNew := schema.Resource {
636+ Schema : map [string ]* schema.Schema {
637+ "prop" : {
638+ Type : schema .TypeSet ,
639+ Optional : true ,
640+ ForceNew : true ,
641+ MaxItems : 1 ,
642+ Elem : & schema.Resource {
643+ Schema : map [string ]* schema.Schema {
644+ "nested_prop" : {
645+ Type : schema .TypeString ,
646+ Optional : true ,
647+ },
648+ },
649+ },
650+ },
651+ },
652+ }
653+
654+ maxItemsOneBlockSchemaNestedForceNew := schema.Resource {
655+ Schema : map [string ]* schema.Schema {
656+ "prop" : {
657+ Type : schema .TypeSet ,
658+ Optional : true ,
659+ MaxItems : 1 ,
660+ Elem : & schema.Resource {
661+ Schema : map [string ]* schema.Schema {
662+ "nested_prop" : {
663+ Type : schema .TypeString ,
664+ Optional : true ,
665+ ForceNew : true ,
666+ },
667+ },
668+ },
669+ },
670+ },
671+ }
672+
673+ diffSchemaValueMakerPairs := []diffSchemaValueMakerPair [[]string ]{
674+ {"max items one attribute" , maxItemsOneAttrSchema , listValueMaker },
675+ {"max items one attribute force new" , maxItemsOneAttrSchemaForceNew , listValueMaker },
676+ {"max items one block" , maxItemsOneBlockSchema , nestedListValueMaker },
677+ {"max items one block force new" , maxItemsOneBlockSchemaForceNew , nestedListValueMaker },
678+ {"max items one block nested force new" , maxItemsOneBlockSchemaNestedForceNew , nestedListValueMaker },
679+ }
680+
681+ runSDKv2TestMatrix (t , diffSchemaValueMakerPairs , oneElementScenarios ())
682+ }
0 commit comments