Skip to content

Commit c48e857

Browse files
author
Cristina Sánchez Sánchez
committed
Added TestNewAtlasUpdateReq
1 parent 542fa5e commit c48e857

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

internal/service/clouduserprojectassignment/model_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,79 @@ func TestNewProjectUserRequest(t *testing.T) {
143143
})
144144
}
145145
}
146+
147+
func TestNewAtlasUpdateReq(t *testing.T) {
148+
ctx := t.Context()
149+
150+
type args struct {
151+
stateRoles []string
152+
planRoles []string
153+
}
154+
tests := []struct {
155+
name string
156+
args args
157+
wantAddRoles []string
158+
wantRemoveRoles []string
159+
}{
160+
{
161+
name: "add and remove roles",
162+
args: args{
163+
stateRoles: []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_READ_ONLY"},
164+
planRoles: []string{"GROUP_OWNER", "GROUP_DATA_ACCESS_READ_ONLY"},
165+
},
166+
wantAddRoles: []string{"GROUP_OWNER"},
167+
wantRemoveRoles: []string{"GROUP_READ_ONLY"},
168+
},
169+
{
170+
name: "no changes",
171+
args: args{
172+
stateRoles: []string{"GROUP_OWNER"},
173+
planRoles: []string{"GROUP_OWNER"},
174+
},
175+
wantAddRoles: []string{},
176+
wantRemoveRoles: []string{},
177+
},
178+
{
179+
name: "all roles removed",
180+
args: args{
181+
stateRoles: []string{"GROUP_OWNER"},
182+
planRoles: []string{},
183+
},
184+
wantAddRoles: []string{},
185+
wantRemoveRoles: []string{"GROUP_OWNER"},
186+
},
187+
{
188+
name: "all roles added",
189+
args: args{
190+
stateRoles: []string{},
191+
planRoles: []string{"GROUP_OWNER"},
192+
},
193+
wantAddRoles: []string{"GROUP_OWNER"},
194+
wantRemoveRoles: []string{},
195+
},
196+
}
197+
198+
for _, tt := range tests {
199+
t.Run(tt.name, func(t *testing.T) {
200+
stateRoles, _ := types.SetValueFrom(ctx, types.StringType, tt.args.stateRoles)
201+
planRoles, _ := types.SetValueFrom(ctx, types.StringType, tt.args.planRoles)
202+
203+
state := &clouduserprojectassignment.TFModel{Roles: stateRoles}
204+
plan := &clouduserprojectassignment.TFModel{Roles: planRoles}
205+
206+
addReqs, removeReqs, diags := clouduserprojectassignment.NewAtlasUpdateReq(ctx, plan, state)
207+
assert.False(t, diags.HasError(), "expected no diagnostics")
208+
209+
var gotAddRoles, gotRemoveRoles []string
210+
for _, r := range addReqs {
211+
gotAddRoles = append(gotAddRoles, r.GroupRole)
212+
}
213+
for _, r := range removeReqs {
214+
gotRemoveRoles = append(gotRemoveRoles, r.GroupRole)
215+
}
216+
217+
assert.ElementsMatch(t, tt.wantAddRoles, gotAddRoles, "add roles mismatch")
218+
assert.ElementsMatch(t, tt.wantRemoveRoles, gotRemoveRoles, "remove roles mismatch")
219+
})
220+
}
221+
}

0 commit comments

Comments
 (0)