@@ -1301,3 +1301,181 @@ func TestCloudProviderRegions_Get(t *testing.T) {
13011301 t .Error (diff )
13021302 }
13031303}
1304+
1305+ func TestClusters_Upgrade (t * testing.T ) {
1306+ client , mux , teardown := setup ()
1307+ defer teardown ()
1308+
1309+ groupID := "1"
1310+ clusterName := "AppData"
1311+
1312+ upgradeRequest := & Cluster {
1313+ ID : "1" ,
1314+ AutoScaling : & AutoScaling {DiskGBEnabled : pointy .Bool (true ),
1315+ Compute : & Compute {Enabled : pointy .Bool (true ), ScaleDownEnabled : pointy .Bool (true )}},
1316+ BackupEnabled : pointy .Bool (true ),
1317+ BiConnector : & BiConnector {Enabled : pointy .Bool (false ), ReadPreference : "secondary" },
1318+ ClusterType : "REPLICASET" ,
1319+ DiskSizeGB : pointy .Float64 (160 ),
1320+ EncryptionAtRestProvider : "AWS" ,
1321+ GroupID : groupID ,
1322+ MongoDBVersion : "3.4.9" ,
1323+ MongoURI : "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017" ,
1324+ MongoURIUpdated : "2017-10-23T21:26:17Z" ,
1325+ MongoURIWithOptions : "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=mongo-shard-0" ,
1326+ Name : clusterName ,
1327+ NumShards : pointy .Int64 (1 ),
1328+ Paused : pointy .Bool (false ),
1329+ ProviderSettings : & ProviderSettings {
1330+ ProviderName : "AWS" ,
1331+ DiskIOPS : pointy .Int64 (1320 ),
1332+ EncryptEBSVolume : pointy .Bool (false ),
1333+ InstanceSizeName : "M40" ,
1334+ RegionName : "US_WEST_2" ,
1335+ AutoScaling : & AutoScaling {Compute : & Compute {MinInstanceSize : "M20" , MaxInstanceSize : "M80" }},
1336+ },
1337+ ReplicationFactor : pointy .Int64 (3 ),
1338+
1339+ ReplicationSpec : map [string ]RegionsConfig {
1340+ "US_EAST_1" : {
1341+ ElectableNodes : pointy .Int64 (3 ),
1342+ Priority : pointy .Int64 (7 ),
1343+ ReadOnlyNodes : pointy .Int64 (0 ),
1344+ },
1345+ },
1346+ SrvAddress : "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017" ,
1347+ StateName : "IDLE" ,
1348+ VersionReleaseSystem : "LTS" ,
1349+ }
1350+
1351+ mux .HandleFunc (fmt .Sprintf ("/api/atlas/v1.0/groups/%s/clusters/tenantUpgrade" , groupID ), func (w http.ResponseWriter , r * http.Request ) {
1352+ expected := map [string ]interface {}{
1353+ "id" : "1" ,
1354+ "autoScaling" : map [string ]interface {}{
1355+ "diskGBEnabled" : true ,
1356+ "compute" : map [string ]interface {}{
1357+ "enabled" : true ,
1358+ "scaleDownEnabled" : true ,
1359+ },
1360+ },
1361+ "backupEnabled" : true ,
1362+ "biConnector" : map [string ]interface {}{
1363+ "enabled" : false ,
1364+ "readPreference" : "secondary" ,
1365+ },
1366+ "clusterType" : "REPLICASET" ,
1367+ "diskSizeGB" : float64 (160 ),
1368+ "encryptionAtRestProvider" : "AWS" ,
1369+ "groupId" : groupID ,
1370+ "mongoDBVersion" : "3.4.9" ,
1371+ "mongoURI" : "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017" ,
1372+ "mongoURIUpdated" : "2017-10-23T21:26:17Z" ,
1373+ "mongoURIWithOptions" : "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=mongo-shard-0" ,
1374+ "name" : "AppData" ,
1375+ "numShards" : float64 (1 ),
1376+ "paused" : false ,
1377+ "providerSettings" : map [string ]interface {}{
1378+ "providerName" : "AWS" ,
1379+ "diskIOPS" : float64 (1320 ),
1380+ "encryptEBSVolume" : false ,
1381+ "instanceSizeName" : "M40" ,
1382+ "regionName" : "US_WEST_2" ,
1383+ "autoScaling" : map [string ]interface {}{
1384+ "compute" : map [string ]interface {}{
1385+ "minInstanceSize" : "M20" ,
1386+ "maxInstanceSize" : "M80" ,
1387+ },
1388+ },
1389+ },
1390+ "replicationFactor" : float64 (3 ),
1391+ "replicationSpec" : map [string ]interface {}{
1392+ "US_EAST_1" : map [string ]interface {}{
1393+ "electableNodes" : float64 (3 ),
1394+ "priority" : float64 (7 ),
1395+ "readOnlyNodes" : float64 (0 ),
1396+ },
1397+ },
1398+ "srvAddress" : "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017" ,
1399+ "stateName" : "IDLE" ,
1400+ "versionReleaseSystem" : "LTS" ,
1401+ }
1402+
1403+ jsonBlob := `
1404+ {
1405+ "autoScaling": {
1406+ "diskGBEnabled": true,
1407+ "compute": {
1408+ "enabled": true,
1409+ "scaleDownEnabled": true
1410+ }
1411+ },
1412+ "backupEnabled": true,
1413+ "biConnector": {
1414+ "enabled": false,
1415+ "readPreference": "secondary"
1416+ },
1417+ "clusterType": "REPLICASET",
1418+ "diskSizeGB": 160,
1419+ "encryptionAtRestProvider": "AWS",
1420+ "groupId": "1",
1421+ "mongoDBVersion": "3.4.9",
1422+ "mongoURI": "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
1423+ "mongoURIUpdated": "2017-10-23T21:26:17Z",
1424+ "mongoURIWithOptions": "mongodb://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=mongo-shard-0",
1425+ "name": "AppData",
1426+ "numShards": 1,
1427+ "paused": false,
1428+ "pitEnabled": false,
1429+ "providerSettings": {
1430+ "providerName": "AWS",
1431+ "diskIOPS": 1320,
1432+ "encryptEBSVolume": false,
1433+ "instanceSizeName": "M40",
1434+ "regionName": "US_WEST_2",
1435+ "autoScaling": {
1436+ "compute": {
1437+ "minInstanceSize": "M10",
1438+ "maxInstanceSize": "M60"
1439+ }
1440+ }
1441+ },
1442+ "replicationFactor": 3,
1443+ "replicationSpec": {
1444+ "US_EAST_1": {
1445+ "electableNodes": 3,
1446+ "priority": 7,
1447+ "readOnlyNodes": 0
1448+ }
1449+ },
1450+ "srvAddress": "mongodb+srv://mongo-shard-00-00.mongodb.net:27017,mongo-shard-00-01.mongodb.net:27017,mongo-shard-00-02.mongodb.net:27017",
1451+ "stateName": "IDLE",
1452+ "versionReleaseSystem": "LTS"
1453+ }
1454+ `
1455+
1456+ var v map [string ]interface {}
1457+ err := json .NewDecoder (r .Body ).Decode (& v )
1458+ if err != nil {
1459+ t .Fatalf ("decode json: %v" , err )
1460+ }
1461+
1462+ if diff := deep .Equal (v , expected ); diff != nil {
1463+ t .Errorf ("Clusters.Update Request Body = %v" , diff )
1464+ }
1465+
1466+ fmt .Fprint (w , jsonBlob )
1467+ })
1468+
1469+ dbUser , _ , err := client .Clusters .Upgrade (ctx , groupID , upgradeRequest )
1470+ if err != nil {
1471+ t .Fatalf ("Clusters.Upgrade returned error: %v" , err )
1472+ }
1473+
1474+ if name := dbUser .Name ; name != clusterName {
1475+ t .Errorf ("expected name '%s', received '%s'" , clusterName , name )
1476+ }
1477+
1478+ if id := dbUser .GroupID ; id != groupID {
1479+ t .Errorf ("expected groupId '%s', received '%s'" , groupID , id )
1480+ }
1481+ }
0 commit comments