Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Azure.Management.ContainerInstance;
using Microsoft.Azure.Management.ContainerInstance.Models;
using Microsoft.Azure.Management.ResourceManager.Models;
using Microsoft.Rest.Azure;
using Xunit;

namespace ContainerInstance.Tests
{
public class ContainerGroupScenarioTests
{
[Fact]
public void ContainerGroupCreateGetDeleteTests()
{
using (TestContext context = new TestContext(this))
{
string containerInstanceLocation = "westus";

ResourceGroup resourceGroup = context.CreateResourceGroup("containergroupcrd-", containerInstanceLocation);
ContainerInstanceManagementClient containerClient = context.GetClient<ContainerInstanceManagementClient>();

string containerGroupName = context.GenerateName("containergroup");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.GenerateName [](start = 32, length = 20)

Just use TestUtilities.GenerateName

string containerOsType = "Linux";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Linux" [](start = 29, length = 7)

Use OperatingSystemTypes.Linux


string containerName = "test1";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test1" [](start = 27, length = 7)

Can you also use TestUtilities.GenerateName to generate a random name?

string containerImage = "nginx";
int containerPort = 80;
double containerCpu = 1;
double containerMemoryInGB = 1.5;

// Add a containergroup with a container
ContainerGroup createdContainerGroup = containerClient.ContainerGroups.CreateOrUpdate(resourceGroup.Name, containerGroupName, new ContainerGroup
{
Location = resourceGroup.Location,
OsType = containerOsType,
Containers = new List<Container>
{
new Container
{
Name = containerName,
Image = containerImage,
Ports = new List<ContainerPort>
{
new ContainerPort(containerPort)
},
Resources = new ResourceRequirements
{
Requests = new ResourceRequests
{
Cpu = containerCpu,
MemoryInGB = containerMemoryInGB
}
}
}
}
});
Assert.NotNull(createdContainerGroup);
Assert.Equal(containerGroupName, createdContainerGroup.Name);
Assert.Equal(containerOsType, createdContainerGroup.OsType);
Assert.Equal(1, createdContainerGroup.Containers.Count);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also verify the there is public IP address assigned.


Container createdContainer = createdContainerGroup.Containers.First();
Assert.Equal(containerName, createdContainer.Name);
Assert.Equal(containerImage, createdContainer.Image);
Assert.Equal(1, createdContainer.Ports.Count);
Assert.Equal(containerPort, createdContainer.Ports.First().Port);
Assert.Equal(containerCpu, createdContainer.Resources.Requests.Cpu);
Assert.Equal(containerMemoryInGB, createdContainer.Resources.Requests.MemoryInGB);

// Wait till the container group is ready before proceeding
ContainerGroupUtilities.WaitTillProvisioningStateSucceeded(containerClient, resourceGroup.Name, containerGroupName);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really necessary. You can call get or list before reach succeeded provisioning state.


string containerGroupID = createdContainerGroup.Id;

// Get the container group
ContainerGroup getContainerGroup = containerClient.ContainerGroups.Get(resourceGroup.Name, containerGroupName);
Assert.NotNull(createdContainerGroup);
Assert.Equal(containerGroupName, getContainerGroup.Name);
Assert.Equal(containerOsType, getContainerGroup.OsType);

Container getContainer = getContainerGroup.Containers.First();
Assert.Equal(containerName, getContainer.Name);
Assert.Equal(containerImage, getContainer.Image);
Assert.Equal(1, getContainer.Ports.Count);
Assert.Equal(containerPort, getContainer.Ports.First().Port);
Assert.Equal(containerCpu, getContainer.Resources.Requests.Cpu);
Assert.Equal(containerMemoryInGB, getContainer.Resources.Requests.MemoryInGB);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap all the assertion into a helper method.


// List the container group within the resource group
IPage<ContainerGroup> listRgContainerGroup = containerClient.ContainerGroups.ListByResourceGroup(resourceGroup.Name);
Assert.NotNull(listRgContainerGroup);
Assert.Equal(1, listRgContainerGroup.Count());
Assert.Equal(containerGroupName, listRgContainerGroup.First().Name);

// List the container group within the subscription
IPage<ContainerGroup> listSubContainerGroup = containerClient.ContainerGroups.List();
Assert.NotNull(listRgContainerGroup);
Assert.True(listRgContainerGroup.Count() >= 1);
Assert.True(listRgContainerGroup.Any(x => containerGroupID.Equals(x?.Id)));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a test case in which you create 2 container group. When listing all, you should get both. When listing by resource group, you should only get one.


// Delete the container group
containerClient.ContainerGroups.Delete(resourceGroup.Name, containerGroupName);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" />
<PropertyGroup>
<PackageId>ContainerInstance.Tests</PackageId>
<AssemblyName>ContainerInstance.Tests</AssemblyName>
<VersionPrefix>1.0.0-preview</VersionPrefix>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>netcoreapp1.1</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Utilities\ContainerInstanceTestUtilities.cs" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottHolden this is not needed. I know VS might have added it, can you remove it. VS will include code files by default in all sub directories.

</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.0.6" />
<PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="2.2.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="11.1.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.2.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="1.2.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="6.5.0-preview" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.4" />
</ItemGroup>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. All not needed.

<ItemGroup>
<ProjectReference Include="..\Management.ContainerInstance\Microsoft.Azure.Management.ContainerInstance.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="SessionRecords\**\*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<ItemGroup>
<Folder Include="SessionRecords\" />
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ScottHolden can you clean up these itemgroup, you do not need a separate directory itemgroup for SessionRecords

</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System.Collections.Generic;
using System.Threading;
using Microsoft.Azure.Management.ContainerInstance;
using Microsoft.Azure.Management.ContainerInstance.Models;
using Microsoft.Azure.Management.ResourceManager.Models;
using Xunit;

namespace ContainerInstance.Tests
{
public class ContainerLogScenarioTests
{
[Fact]
public void ContainerLogGetTest()
{
using (TestContext context = new TestContext(this))
{
string containerInstanceLocation = "westus";

ResourceGroup resourceGroup = context.CreateResourceGroup("containerlogget-", containerInstanceLocation);
ContainerInstanceManagementClient containerClient = context.GetClient<ContainerInstanceManagementClient>();

string containerGroupName = context.GenerateName("containergroup");
string containerOsType = "Linux";
string containerName = "test1";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the other scenario tests. Use built in function to generate name.

string containerImage = "nginx";
int containerPort = 80;
double containerCpu = 1;
double containerMemoryInGB = 1.5;

// Create an empty container group
ContainerGroup createdContainerGroup = containerClient.ContainerGroups.CreateOrUpdate(resourceGroup.Name, containerGroupName, new ContainerGroup
{
Location = resourceGroup.Location,
OsType = containerOsType,
Containers = new List<Container>
{
new Container
{
Name = containerName,
Image = containerImage,
Ports = new List<ContainerPort>
{
new ContainerPort(containerPort)
},
Resources = new ResourceRequirements
{
Requests = new ResourceRequests
{
Cpu = containerCpu,
MemoryInGB = containerMemoryInGB
}
}
}
}
});
Assert.NotNull(createdContainerGroup);

// Wait till ready
ContainerGroupUtilities.WaitTillProvisioningStateSucceeded(containerClient, resourceGroup.Name, containerGroupName);

// Check that we can list the logs
Logs logs = containerClient.ContainerLogs.List(resourceGroup.Name, containerName, containerGroupName);
Assert.NotNull(logs);
Assert.NotNull(logs.Content);

// Delete the container group
containerClient.ContainerGroups.Delete(resourceGroup.Name, containerGroupName);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Reflection;
using System.Runtime.InteropServices;
using Xunit;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ContainerInstance.Tests")]
[assembly: AssemblyTrademark("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ef989c56-f585-40a2-8af6-18789546f5bf")]
Loading