@@ -35,7 +35,7 @@ func Test_networkResourceAPIToTerraform(t *testing.T) {
3535 Description : types .StringNull (),
3636 Address : types .StringValue ("1.1.1.1/32" ),
3737 Enabled : types .BoolValue (false ),
38- Groups : types .ListValueMust (types .StringType , []attr.Value {}),
38+ Groups : types .SetValueMust (types .StringType , []attr.Value {}),
3939 },
4040 },
4141 {
@@ -62,7 +62,41 @@ func Test_networkResourceAPIToTerraform(t *testing.T) {
6262 Description : types .StringValue ("Test" ),
6363 Address : types .StringValue ("example.com" ),
6464 Enabled : types .BoolValue (true ),
65- Groups : types .ListValueMust (types .StringType , []attr.Value {types .StringValue ("g1" )}),
65+ Groups : types .SetValueMust (types .StringType , []attr.Value {types .StringValue ("g1" )}),
66+ },
67+ },
68+ {
69+ resource : & api.NetworkResource {
70+ Address : "example.com" ,
71+ Description : valPtr ("Test" ),
72+ Enabled : true ,
73+ Groups : []api.GroupMinimum {
74+ {
75+ Id : "g1" ,
76+ Name : "not important" ,
77+ Issued : nil ,
78+ PeersCount : 0 ,
79+ ResourcesCount : 0 ,
80+ },
81+ {
82+ Id : "g2" ,
83+ Name : "doesn't matter" ,
84+ Issued : nil ,
85+ PeersCount : 0 ,
86+ ResourcesCount : 0 ,
87+ },
88+ },
89+ Id : "r2" ,
90+ Name : "test2" ,
91+ Type : api .NetworkResourceTypeDomain ,
92+ },
93+ expected : NetworkResourceModel {
94+ Id : types .StringValue ("r2" ),
95+ Name : types .StringValue ("test2" ),
96+ Description : types .StringValue ("Test" ),
97+ Address : types .StringValue ("example.com" ),
98+ Enabled : types .BoolValue (true ),
99+ Groups : types .SetValueMust (types .StringType , []attr.Value {types .StringValue ("g1" ), types .StringValue ("g2" )}),
66100 },
67101 },
68102 }
@@ -89,12 +123,11 @@ func Test_NetworkResource_Create(t *testing.T) {
89123 Steps : []resource.TestStep {
90124 {
91125 ResourceName : rName ,
92- Config : testNetworkResourceResource (rName , "network1" , `example.com` , `["group-notall"]` , rName ),
126+ Config : testNetworkResourceResource (rName , "network1" , `example.com` , `["group-notall", "group-all" ]` , rName ),
93127 Check : resource .ComposeAggregateTestCheckFunc (
94128 resource .TestCheckResourceAttrSet (rNameFull , "id" ),
95129 resource .TestCheckResourceAttr (rNameFull , "address" , "example.com" ),
96- resource .TestCheckResourceAttr (rNameFull , "groups.#" , "1" ),
97- resource .TestCheckResourceAttr (rNameFull , "groups.0" , "group-notall" ),
130+ resource .TestCheckResourceAttr (rNameFull , "groups.#" , "2" ),
98131 resource .TestCheckResourceAttr (rNameFull , "name" , rName ),
99132 func (s * terraform.State ) error {
100133 nreID := s .RootModule ().Resources [rNameFull ].Primary .Attributes ["id" ]
@@ -107,8 +140,8 @@ func Test_NetworkResource_Create(t *testing.T) {
107140 return fmt .Errorf ("NetworkResource Address mismatch, expected example.com, found %s on management server" , resource .Address )
108141 }
109142
110- if len (resource .Groups ) != 1 || resource .Groups [0 ].Id != "group-notall" {
111- return fmt .Errorf ("NetworkResource Groups mismatch, expected [group-notall], found %#v on management server" , resource .Groups )
143+ if len (resource .Groups ) != 2 || ( resource .Groups [0 ].Id != "group-notall" && resource . Groups [ 0 ]. Id != "group-all" ) && ( resource . Groups [ 1 ]. Id != "group-notall" && resource . Groups [ 1 ]. Id != "group-all" ) {
144+ return fmt .Errorf ("NetworkResource Groups mismatch, expected [group-notall, group-all ], found %#v on management server" , resource .Groups )
112145 }
113146
114147 if resource .Name != rName {
@@ -139,11 +172,10 @@ func Test_NetworkResource_Update(t *testing.T) {
139172 },
140173 {
141174 ResourceName : rName ,
142- Config : testNetworkResourceResource (rName , "network1" , `google.com` , `["group-all"]` , rName + "Updated" ),
175+ Config : testNetworkResourceResource (rName , "network1" , `google.com` , `["group-all", "group-notall" ]` , rName + "Updated" ),
143176 Check : resource .ComposeAggregateTestCheckFunc (
144177 resource .TestCheckResourceAttr (rNameFull , "address" , "google.com" ),
145- resource .TestCheckResourceAttr (rNameFull , "groups.#" , "1" ),
146- resource .TestCheckResourceAttr (rNameFull , "groups.0" , "group-all" ),
178+ resource .TestCheckResourceAttr (rNameFull , "groups.#" , "2" ),
147179 resource .TestCheckResourceAttr (rNameFull , "name" , rName + "Updated" ),
148180 func (s * terraform.State ) error {
149181 nreID := s .RootModule ().Resources [rNameFull ].Primary .Attributes ["id" ]
@@ -156,8 +188,8 @@ func Test_NetworkResource_Update(t *testing.T) {
156188 return fmt .Errorf ("NetworkResource Address mismatch, expected google.com, found %s on management server" , resource .Address )
157189 }
158190
159- if len (resource .Groups ) != 1 || resource .Groups [0 ].Id != "group-all" {
160- return fmt .Errorf ("NetworkResource Groups mismatch, expected [group-all], found %#v on management server" , resource .Groups )
191+ if len (resource .Groups ) != 2 || ( resource .Groups [0 ].Id != "group-notall" && resource . Groups [ 0 ]. Id != "group- all") && ( resource . Groups [ 1 ]. Id != "group-notall" && resource . Groups [ 1 ]. Id != "group-all" ) {
192+ return fmt .Errorf ("NetworkResource Groups mismatch, expected [group-notall, group- all], found %#v on management server" , resource .Groups )
161193 }
162194
163195 if resource .Name != rName + "Updated" {
0 commit comments