@@ -1277,3 +1277,148 @@ func TestIsSSHPublicKeysUpToDate(t *testing.T) {
12771277 })
12781278 }
12791279}
1280+
1281+ func TestIsMappingUpToDate (t * testing.T ) {
1282+ type args struct {
1283+ cr * svcapitypes.User
1284+ obj * svcsdk.DescribeUserOutput
1285+ }
1286+
1287+ type want struct {
1288+ isUpToDate bool
1289+ }
1290+
1291+ cases := map [string ]struct {
1292+ args
1293+ want
1294+ }{
1295+ "NeedsUpdate" : {
1296+ args : args {
1297+ cr : user (
1298+ withExternalName ("test" ),
1299+ withSpec (svcapitypes.UserParameters {
1300+ Region : "us-east-1" ,
1301+ HomeDirectoryMappings : []* svcapitypes.HomeDirectoryMapEntry {
1302+ {
1303+ Entry : ptr .To ("entry" ),
1304+ Target : ptr .To ("target" ),
1305+ },
1306+ },
1307+ CustomUserParameters : svcapitypes.CustomUserParameters {
1308+ ServerID : ptr .To ("server" ),
1309+ Role : ptr .To ("role" ),
1310+ SSHPublicKeys : []svcapitypes.SSHPublicKeySpec {
1311+ {
1312+ Body : "some-public-key" ,
1313+ },
1314+ },
1315+ },
1316+ }),
1317+ withStatus (svcapitypes.UserObservation {
1318+ ARN : ptr .To ("ARN" ),
1319+ }),
1320+ ),
1321+ obj : & svcsdk.DescribeUserOutput {
1322+ User : & svcsdk.DescribedUser {
1323+ HomeDirectoryMappings : []* svcsdk.HomeDirectoryMapEntry {},
1324+ },
1325+ },
1326+ },
1327+ want : want {
1328+ isUpToDate : false ,
1329+ },
1330+ },
1331+ "NeedsUpdateNewTarget" : {
1332+ args : args {
1333+ cr : user (
1334+ withExternalName ("test" ),
1335+ withSpec (svcapitypes.UserParameters {
1336+ Region : "us-east-1" ,
1337+ HomeDirectoryMappings : []* svcapitypes.HomeDirectoryMapEntry {
1338+ {
1339+ Entry : ptr .To ("entry" ),
1340+ Target : ptr .To ("targetnew" ),
1341+ },
1342+ },
1343+ CustomUserParameters : svcapitypes.CustomUserParameters {
1344+ ServerID : ptr .To ("server" ),
1345+ Role : ptr .To ("role" ),
1346+ SSHPublicKeys : []svcapitypes.SSHPublicKeySpec {
1347+ {
1348+ Body : "some-public-key" ,
1349+ },
1350+ },
1351+ },
1352+ }),
1353+ withStatus (svcapitypes.UserObservation {
1354+ ARN : ptr .To ("ARN" ),
1355+ }),
1356+ ),
1357+ obj : & svcsdk.DescribeUserOutput {
1358+ User : & svcsdk.DescribedUser {
1359+ HomeDirectoryMappings : []* svcsdk.HomeDirectoryMapEntry {
1360+ {
1361+ Entry : ptr .To ("entry" ),
1362+ Target : ptr .To ("target" ),
1363+ },
1364+ },
1365+ },
1366+ },
1367+ },
1368+ want : want {
1369+ isUpToDate : false ,
1370+ },
1371+ },
1372+ "IsUpToDate" : {
1373+ args : args {
1374+ cr : user (
1375+ withExternalName ("test" ),
1376+ withSpec (svcapitypes.UserParameters {
1377+ Region : "us-east-1" ,
1378+ HomeDirectoryMappings : []* svcapitypes.HomeDirectoryMapEntry {
1379+ {
1380+ Entry : ptr .To ("entry" ),
1381+ Target : ptr .To ("target" ),
1382+ },
1383+ },
1384+ CustomUserParameters : svcapitypes.CustomUserParameters {
1385+ ServerID : ptr .To ("server" ),
1386+ Role : ptr .To ("role" ),
1387+ SSHPublicKeys : []svcapitypes.SSHPublicKeySpec {
1388+ {
1389+ Body : "some-public-key" ,
1390+ },
1391+ },
1392+ },
1393+ }),
1394+ withStatus (svcapitypes.UserObservation {
1395+ ARN : ptr .To ("ARN" ),
1396+ }),
1397+ ),
1398+ obj : & svcsdk.DescribeUserOutput {
1399+ User : & svcsdk.DescribedUser {
1400+ HomeDirectoryMappings : []* svcsdk.HomeDirectoryMapEntry {
1401+ {
1402+ Entry : ptr .To ("entry" ),
1403+ Target : ptr .To ("target" ),
1404+ },
1405+ },
1406+ },
1407+ },
1408+ },
1409+ want : want {
1410+ isUpToDate : true ,
1411+ },
1412+ },
1413+ }
1414+
1415+ for name , tc := range cases {
1416+ t .Run (name , func (t * testing.T ) {
1417+ isUpToDate := isMappingsUpToDate (tc .args .cr , tc .args .obj )
1418+
1419+ if diff := cmp .Diff (tc .want .isUpToDate , isUpToDate , test .EquateErrors ()); diff != "" {
1420+ t .Errorf ("isUpToDate: -want, +got:\n %s" , diff )
1421+ }
1422+ })
1423+ }
1424+ }
0 commit comments