|
4 | 4 | "testing"
|
5 | 5 | "time"
|
6 | 6 |
|
| 7 | + "github.com/hashicorp/terraform-plugin-framework/attr" |
7 | 8 | "github.com/hashicorp/terraform-plugin-framework/types"
|
8 | 9 | "github.com/mongodb/terraform-provider-mongodbatlas/internal/service/clouduserprojectassignment"
|
9 | 10 | "github.com/stretchr/testify/assert"
|
@@ -92,6 +93,39 @@ func TestCloudUserProjectAssignmentSDKToTFModel(t *testing.T) {
|
92 | 93 | SDKResp: fullResp,
|
93 | 94 | expectedTFModel: expectedFullModel,
|
94 | 95 | },
|
| 96 | + "Empty SDK response": { |
| 97 | + SDKResp: &admin.GroupUserResponse{ |
| 98 | + Id: "", |
| 99 | + Username: "", |
| 100 | + FirstName: nil, |
| 101 | + LastName: nil, |
| 102 | + Country: nil, |
| 103 | + MobileNumber: nil, |
| 104 | + OrgMembershipStatus: "", |
| 105 | + CreatedAt: nil, |
| 106 | + LastAuth: nil, |
| 107 | + InvitationCreatedAt: nil, |
| 108 | + InvitationExpiresAt: nil, |
| 109 | + InviterUsername: nil, |
| 110 | + Roles: nil, |
| 111 | + }, |
| 112 | + expectedTFModel: &clouduserprojectassignment.TFModel{ |
| 113 | + UserId: types.StringValue(""), |
| 114 | + Username: types.StringValue(""), |
| 115 | + ProjectId: types.StringValue(testProjectID), |
| 116 | + FirstName: types.StringNull(), |
| 117 | + LastName: types.StringNull(), |
| 118 | + Country: types.StringNull(), |
| 119 | + MobileNumber: types.StringNull(), |
| 120 | + OrgMembershipStatus: types.StringValue(""), |
| 121 | + CreatedAt: types.StringNull(), |
| 122 | + LastAuth: types.StringNull(), |
| 123 | + InvitationCreatedAt: types.StringNull(), |
| 124 | + InvitationExpiresAt: types.StringNull(), |
| 125 | + InviterUsername: types.StringNull(), |
| 126 | + Roles: types.SetNull(types.StringType), |
| 127 | + }, |
| 128 | + }, |
95 | 129 | }
|
96 | 130 |
|
97 | 131 | for testName, tc := range testCases {
|
@@ -133,6 +167,26 @@ func TestNewProjectUserRequest(t *testing.T) {
|
133 | 167 | Roles: testProjectRoles,
|
134 | 168 | },
|
135 | 169 | },
|
| 170 | + "Nil model": { |
| 171 | + plan: &clouduserprojectassignment.TFModel{ |
| 172 | + Username: types.StringNull(), |
| 173 | + Roles: types.SetNull(types.StringType), |
| 174 | + }, |
| 175 | + expected: &admin.GroupUserRequest{ |
| 176 | + Username: "", |
| 177 | + Roles: []string{}, |
| 178 | + }, |
| 179 | + }, |
| 180 | + "Empty model": { |
| 181 | + plan: &clouduserprojectassignment.TFModel{ |
| 182 | + Username: types.StringValue(""), |
| 183 | + Roles: types.SetValueMust(types.StringType, []attr.Value{}), |
| 184 | + }, |
| 185 | + expected: &admin.GroupUserRequest{ |
| 186 | + Username: "", |
| 187 | + Roles: []string{}, |
| 188 | + }, |
| 189 | + }, |
136 | 190 | }
|
137 | 191 |
|
138 | 192 | for name, tc := range testCases {
|
@@ -193,6 +247,15 @@ func TestNewAtlasUpdateReq(t *testing.T) {
|
193 | 247 | wantAddRoles: []string{"GROUP_OWNER"},
|
194 | 248 | wantRemoveRoles: []string{},
|
195 | 249 | },
|
| 250 | + { |
| 251 | + name: "nil roles", |
| 252 | + args: args{ |
| 253 | + stateRoles: nil, |
| 254 | + planRoles: []string{}, |
| 255 | + }, |
| 256 | + wantAddRoles: []string{}, |
| 257 | + wantRemoveRoles: []string{}, |
| 258 | + }, |
196 | 259 | }
|
197 | 260 |
|
198 | 261 | for _, tt := range tests {
|
|
0 commit comments