Skip to content

Commit

Permalink
Cosmos DB: update 2019 08 preview (#903)
Browse files Browse the repository at this point in the history
* re-gen cosmosdb with package-2019-08-preview, with local extensiontion for redirect fix

* fix: compile error, DatabaseAccountInner -> DatabaseAccountGetResultsInner, SqlDatabaseInner -> SqlDatabaseGetResultsInner

* feat: update interface in domain from java generation

* feat: impl interface for privateEndpointConnection, privateLinkResource and MetadataWriteAccess

* feat: use PATCH method for update

* fix: logic error in test

* feat: update session record

* fix: collection check and use update in test instead of define

* fix: update child resource when get from server

* fix by pr comment: delete duplicate comment, return readonly value, impl class to internal

* fix: remove and sort usings
  • Loading branch information
ChenTanyi authored Nov 25, 2019
1 parent 5650b4c commit 9f07964
Show file tree
Hide file tree
Showing 128 changed files with 45,110 additions and 48,839 deletions.
100 changes: 98 additions & 2 deletions Tests/Fluent.Tests/CosmosDB/CosmosDBTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using Microsoft.Azure.Management.CosmosDB.Fluent;
using Microsoft.Azure.Management.CosmosDB.Fluent.Models;
using Microsoft.Azure.Management.Network.Fluent.Models;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Core;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using System.Collections.Generic;
using Xunit;

namespace Fluent.Tests
Expand Down Expand Up @@ -70,7 +72,6 @@ public void CosmosDBCRUD()
}
catch { }
}

}
}

Expand Down Expand Up @@ -172,7 +173,102 @@ public void CanCreateCassandraCosmosDB()
catch { }
}
}
}

[Fact]
public void CanCreateSqlPrivateEndpoint()
{
using (var context = FluentMockContext.Start(GetType().FullName))
{
var dbName = SdkContext.RandomResourceName("cosmosdb", 22);
var rgName = SdkContext.RandomResourceName("cosmosdbRg", 22);
var networkName = SdkContext.RandomResourceName("network", 22);
var subnetName = SdkContext.RandomResourceName("subnet", 22);
var plsConnectionName = SdkContext.RandomResourceName("plsconnect", 22);
var pedName = SdkContext.RandomResourceName("ped", 22);
var region = Region.USWest;

var azure = TestHelper.CreateRollupClient();

try
{
azure.ResourceGroups.Define(rgName)
.WithRegion(region)
.Create();

var network = azure.Networks.Define(networkName)
.WithRegion(region)
.WithExistingResourceGroup(rgName)
.WithAddressSpace("10.0.0.0/16")
.DefineSubnet(subnetName)
.WithAddressPrefix("10.0.0.0/24")
.WithAccessFromService(ServiceEndpointType.MicrosoftAzureCosmosDB)
.Attach()
.Create();

network.Subnets[subnetName].Inner.PrivateEndpointNetworkPolicies = "Disabled";
network.Subnets[subnetName].Inner.PrivateLinkServiceNetworkPolicies = "Disabled";

network.Update()
.UpdateSubnet(subnetName)
.Parent()
.Apply();

var databaseAccount = azure.CosmosDBAccounts.Define(dbName)
.WithRegion(region)
.WithExistingResourceGroup(rgName)
.WithDataModelSql()
.WithStrongConsistency()
.WithDisableKeyBaseMetadataWriteAccess(true)
.Create();

Assert.True(databaseAccount.KeyBasedMetadataWriteAccessDisabled);

var privateLinkServiceConnection = new PrivateLinkServiceConnectionInner(null,
databaseAccount.Id,
new List<string> { "Sql" },
null,
new PrivateLinkServiceConnectionState("Approved"),
plsConnectionName);

var privateEndpoint = new PrivateEndpointInner(region.ToString(),
null,
pedName,
null,
null,
network.Subnets[subnetName].Inner,
null,
null,
new List<PrivateLinkServiceConnectionInner> { privateLinkServiceConnection },
null);

azure.Networks.Manager.Inner.PrivateEndpoints
.CreateOrUpdateWithHttpMessagesAsync(rgName, pedName, privateEndpoint).Wait();

Assert.Equal("Approved", databaseAccount.GetPrivateEndpointConnection(pedName).PrivateLinkServiceConnectionState.Status);

databaseAccount.Update()
.UpdatePrivateEndpointConnection(pedName)
.WithStatus("Rejected")
.WithDescription("Rej")
.Parent()
.Apply();

var connections = databaseAccount.ListPrivateEndpointConnection();
Assert.True(connections.ContainsKey(pedName));
Assert.Equal("Rejected", connections[pedName].PrivateLinkServiceConnectionState.Status);

Assert.Equal(1, databaseAccount.ListPrivateLinkResources().Count);
}
finally
{
try
{
azure.ResourceGroups.DeleteByName(rgName);
}
catch { }
}
}
}
}
}
}
Loading

0 comments on commit 9f07964

Please sign in to comment.