-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add Azure container instance net SDK #3615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/SDKs/ContainerInstance/ContainerInstance.Tests/ContainerInstance.Tests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" /> | ||
| <PropertyGroup> | ||
| <PackageId>ContainerInstance.Tests</PackageId> | ||
| <Description>ContainerInstance.Tests Class Library</Description> | ||
| <AssemblyName>ContainerInstance.Tests</AssemblyName> | ||
| <VersionPrefix>1.0.0-preview</VersionPrefix> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>netcoreapp1.1</TargetFrameworks> | ||
| <StartupObject></StartupObject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- When xunit cannot detect tests, uncomment the following dependencies --> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yolo3301 remove commented code |
||
| <!-- <PackageReference Include="xunit" Version="2.3.0-beta1-build3642" /> | ||
| <PackageReference Include="xunit.runner.visualstudio" Version="2.3.0-beta1-build1309" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170222-09" /> --> | ||
| <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> | ||
|
|
||
| </Project> | ||
80 changes: 80 additions & 0 deletions
80
src/SDKs/ContainerInstance/ContainerInstance.Tests/Helpers/ContainerInstanceTestUtilities.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Collections.Generic; | ||
| using Microsoft.Azure.Management.ContainerInstance; | ||
| using Microsoft.Azure.Management.ContainerInstance.Models; | ||
| using Microsoft.Azure.Management.Resources; | ||
| using Microsoft.Azure.Management.Resources.Models; | ||
| using Microsoft.Rest.ClientRuntime.Azure.TestFramework; | ||
| using Xunit; | ||
|
|
||
| namespace ContainerInstance.Tests | ||
| { | ||
| public class ContainerInstanceTestUtilities | ||
| { | ||
| public static ResourceManagementClient GetResourceManagementClient(MockContext context, RecordedDelegatingHandler handler) | ||
| { | ||
| handler.IsPassThrough = true; | ||
| var client = context.GetServiceClient<ResourceManagementClient>(handlers: handler); | ||
| return client; | ||
| } | ||
|
|
||
| public static ContainerInstanceManagementClient GetContainerInstanceManagementClient(MockContext context, RecordedDelegatingHandler handler) | ||
| { | ||
| handler.IsPassThrough = true; | ||
| var client = context.GetServiceClient<ContainerInstanceManagementClient>(handlers: handler); | ||
| return client; | ||
| } | ||
|
|
||
| public static ResourceGroup CreateResourceGroup(ResourceManagementClient client) | ||
| { | ||
| var resourceGroupName = TestUtilities.GenerateName("aci_rg"); | ||
|
|
||
| return client.ResourceGroups.CreateOrUpdate(resourceGroupName, new ResourceGroup | ||
| { | ||
| Location = "westus" | ||
| }); | ||
| } | ||
|
|
||
| public static ContainerGroup CreateTestContainerGroup(string containerGroupName) | ||
| { | ||
| var containers = new Container[] | ||
| { | ||
| new Container( | ||
| name: containerGroupName, | ||
| image: "nginx:latest", | ||
| ports: new List<ContainerPort>() { new ContainerPort(80) }, | ||
| resources: new ResourceRequirements(requests: new ResourceRequests(memoryInGB: 1.5, cpu: 1.0))) | ||
| }; | ||
|
|
||
| var ipAddress = new IpAddress( | ||
| new List<Port>() { new Port(80, "TCP") }); | ||
|
|
||
| var containerGroup = new ContainerGroup( | ||
| name: containerGroupName, | ||
| location: "westus", | ||
| osType: OperatingSystemTypes.Linux, | ||
| ipAddress: ipAddress, | ||
| containers: containers); | ||
|
|
||
| return containerGroup; | ||
| } | ||
|
|
||
| public static void VerifyContainerGroupProperties(ContainerGroup expected, ContainerGroup actual) | ||
| { | ||
| Assert.NotNull(actual); | ||
| Assert.Equal(expected.Name, actual.Name); | ||
| Assert.Equal(expected.Location, actual.Location); | ||
| Assert.Equal(expected.OsType, actual.OsType); | ||
| Assert.NotNull(actual.Containers); | ||
| Assert.Equal(1, actual.Containers.Count); | ||
| Assert.NotNull(actual.IpAddress); | ||
| Assert.NotNull(actual.IpAddress.Ip); | ||
| Assert.Equal(expected.Containers[0].Name, actual.Containers[0].Name); | ||
| Assert.Equal(expected.Containers[0].Image, actual.Containers[0].Image); | ||
| Assert.Equal(expected.Containers[0].Resources.Requests.Cpu, actual.Containers[0].Resources.Requests.Cpu); | ||
| Assert.Equal(expected.Containers[0].Resources.Requests.MemoryInGB, actual.Containers[0].Resources.Requests.MemoryInGB); | ||
| } | ||
| } | ||
| } |
90 changes: 90 additions & 0 deletions
90
src/SDKs/ContainerInstance/ContainerInstance.Tests/Helpers/RecordedDelegatingHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Net.Http.Headers; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace ContainerInstance.Tests | ||
| { | ||
| public class RecordedDelegatingHandler : DelegatingHandler | ||
| { | ||
| private HttpResponseMessage _response; | ||
|
|
||
| public RecordedDelegatingHandler() | ||
| { | ||
| StatusCodeToReturn = HttpStatusCode.Created; | ||
| SubsequentStatusCodeToReturn = StatusCodeToReturn; | ||
| } | ||
|
|
||
| public RecordedDelegatingHandler(HttpResponseMessage response) | ||
| { | ||
| StatusCodeToReturn = HttpStatusCode.Created; | ||
| SubsequentStatusCodeToReturn = StatusCodeToReturn; | ||
| _response = response; | ||
| } | ||
|
|
||
| public HttpStatusCode StatusCodeToReturn { get; set; } | ||
|
|
||
| public HttpStatusCode SubsequentStatusCodeToReturn { get; set; } | ||
|
|
||
| public string Request { get; private set; } | ||
|
|
||
| public HttpRequestHeaders RequestHeaders { get; private set; } | ||
|
|
||
| public HttpContentHeaders ContentHeaders { get; private set; } | ||
|
|
||
| public HttpMethod Method { get; private set; } | ||
|
|
||
| public Uri Uri { get; private set; } | ||
|
|
||
| public bool IsPassThrough { get; set; } | ||
|
|
||
| private int counter; | ||
|
|
||
| protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) | ||
| { | ||
| counter++; | ||
| // Save request | ||
| if (request.Content == null) | ||
| { | ||
| Request = string.Empty; | ||
| } | ||
| else | ||
| { | ||
| Request = await request.Content.ReadAsStringAsync(); | ||
| } | ||
| RequestHeaders = request.Headers; | ||
| if (request.Content != null) | ||
| { | ||
| ContentHeaders = request.Content.Headers; | ||
| } | ||
| Method = request.Method; | ||
| Uri = request.RequestUri; | ||
|
|
||
| // Prepare response | ||
| if (IsPassThrough) | ||
| { | ||
| return await base.SendAsync(request, cancellationToken); | ||
| } | ||
| else | ||
| { | ||
| if (_response != null && counter == 1) | ||
| { | ||
| return _response; | ||
| } | ||
| else | ||
| { | ||
| var statusCode = StatusCodeToReturn; | ||
| if (counter > 1) | ||
| statusCode = SubsequentStatusCodeToReturn; | ||
| HttpResponseMessage response = new HttpResponseMessage(statusCode); | ||
| response.Content = new StringContent(""); | ||
| return response; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
src/SDKs/ContainerInstance/ContainerInstance.Tests/Properties/AssemblyInfo.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
|
||
| using System.Reflection; | ||
| using System.Runtime.CompilerServices; | ||
| 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: AssemblyTitle("ContainerInstance.Tests")] | ||
| [assembly: AssemblyDescription("")] | ||
| [assembly: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("ContainerInstance.Tests")] | ||
| [assembly: AssemblyCopyright("Copyright © 2016")] | ||
| [assembly: AssemblyTrademark("")] | ||
| [assembly: AssemblyCulture("")] | ||
|
|
||
| // 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)] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
|
|
||
| // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
| [assembly: Guid("80C5B642-F93C-4E68-9B37-04565D3CF6AB")] | ||
| [assembly: AssemblyVersion("1.0.0.0")] | ||
| [assembly: AssemblyFileVersion("1.0.0.0")] | ||
137 changes: 137 additions & 0 deletions
137
...onRecords/ContainerInstance.Tests.ContainerInstanceTests/ContainerInstanceCreateTest.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| { | ||
| "Entries": [ | ||
| { | ||
| "RequestUri": "/subscriptions/6987baff-3f62-48c9-a604-3432d813f7e6/resourcegroups/aci_rg7133?api-version=2015-11-01", | ||
| "EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNjk4N2JhZmYtM2Y2Mi00OGM5LWE2MDQtMzQzMmQ4MTNmN2U2L3Jlc291cmNlZ3JvdXBzL2FjaV9yZzcxMzM/YXBpLXZlcnNpb249MjAxNS0xMS0wMQ==", | ||
| "RequestMethod": "PUT", | ||
| "RequestBody": "{\r\n \"location\": \"westus\"\r\n}", | ||
| "RequestHeaders": { | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Content-Length": [ | ||
| "28" | ||
| ], | ||
| "x-ms-client-request-id": [ | ||
| "0f03cad0-3a92-4c4f-aa61-7f877e4a00b9" | ||
| ], | ||
| "accept-language": [ | ||
| "en-US" | ||
| ], | ||
| "User-Agent": [ | ||
| "FxVersion/4.6.25211.01", | ||
| "Microsoft.Azure.Management.Resources.ResourceManagementClient/1.0.0.0" | ||
| ] | ||
| }, | ||
| "ResponseBody": "{\r\n \"id\": \"/subscriptions/6987baff-3f62-48c9-a604-3432d813f7e6/resourceGroups/aci_rg7133\",\r\n \"name\": \"aci_rg7133\",\r\n \"location\": \"westus\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n }\r\n}", | ||
| "ResponseHeaders": { | ||
| "Content-Length": [ | ||
| "173" | ||
| ], | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Expires": [ | ||
| "-1" | ||
| ], | ||
| "Cache-Control": [ | ||
| "no-cache" | ||
| ], | ||
| "Date": [ | ||
| "Tue, 22 Aug 2017 20:50:54 GMT" | ||
| ], | ||
| "Pragma": [ | ||
| "no-cache" | ||
| ], | ||
| "x-ms-ratelimit-remaining-subscription-writes": [ | ||
| "1197" | ||
| ], | ||
| "x-ms-request-id": [ | ||
| "49e9ad80-fe75-4b14-94a3-533597114274" | ||
| ], | ||
| "x-ms-correlation-request-id": [ | ||
| "49e9ad80-fe75-4b14-94a3-533597114274" | ||
| ], | ||
| "x-ms-routing-request-id": [ | ||
| "WESTUS:20170822T205055Z:49e9ad80-fe75-4b14-94a3-533597114274" | ||
| ], | ||
| "Strict-Transport-Security": [ | ||
| "max-age=31536000; includeSubDomains" | ||
| ] | ||
| }, | ||
| "StatusCode": 201 | ||
| }, | ||
| { | ||
| "RequestUri": "/subscriptions/6987baff-3f62-48c9-a604-3432d813f7e6/resourceGroups/aci_rg7133/providers/Microsoft.ContainerInstance/containerGroups/acinetsdk3461?api-version=2017-08-01-preview", | ||
| "EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvNjk4N2JhZmYtM2Y2Mi00OGM5LWE2MDQtMzQzMmQ4MTNmN2U2L3Jlc291cmNlR3JvdXBzL2FjaV9yZzcxMzMvcHJvdmlkZXJzL01pY3Jvc29mdC5Db250YWluZXJJbnN0YW5jZS9jb250YWluZXJHcm91cHMvYWNpbmV0c2RrMzQ2MT9hcGktdmVyc2lvbj0yMDE3LTA4LTAxLXByZXZpZXc=", | ||
| "RequestMethod": "PUT", | ||
| "RequestBody": "{\r\n \"properties\": {\r\n \"containers\": [\r\n {\r\n \"name\": \"acinetsdk3461\",\r\n \"properties\": {\r\n \"image\": \"nginx:latest\",\r\n \"ports\": [\r\n {\r\n \"port\": 80\r\n }\r\n ],\r\n \"resources\": {\r\n \"requests\": {\r\n \"memoryInGB\": 1.5,\r\n \"cpu\": 1.0\r\n }\r\n }\r\n }\r\n }\r\n ],\r\n \"ipAddress\": {\r\n \"ports\": [\r\n {\r\n \"protocol\": \"TCP\",\r\n \"port\": 80\r\n }\r\n ],\r\n \"type\": \"Public\"\r\n },\r\n \"osType\": \"Linux\"\r\n },\r\n \"location\": \"westus\"\r\n}", | ||
| "RequestHeaders": { | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Content-Length": [ | ||
| "616" | ||
| ], | ||
| "x-ms-client-request-id": [ | ||
| "c99141ec-f9d1-4cee-90b2-6116a00f3062" | ||
| ], | ||
| "accept-language": [ | ||
| "en-US" | ||
| ], | ||
| "User-Agent": [ | ||
| "FxVersion/4.6.25211.01", | ||
| "Microsoft.Azure.Management.ContainerInstance.ContainerInstanceManagementClient/1.2.0.0" | ||
| ] | ||
| }, | ||
| "ResponseBody": "{\r\n \"properties\": {\r\n \"provisioningState\": \"Creating\",\r\n \"containers\": [\r\n {\r\n \"name\": \"acinetsdk3461\",\r\n \"properties\": {\r\n \"image\": \"nginx:latest\",\r\n \"ports\": [\r\n {\r\n \"port\": 80\r\n }\r\n ],\r\n \"environmentVariables\": [],\r\n \"resources\": {\r\n \"requests\": {\r\n \"memoryInGB\": 1.5,\r\n \"cpu\": 1.0\r\n }\r\n }\r\n }\r\n }\r\n ],\r\n \"ipAddress\": {\r\n \"ports\": [\r\n {\r\n \"protocol\": \"TCP\",\r\n \"port\": 80\r\n }\r\n ],\r\n \"ip\": \"13.64.187.73\",\r\n \"type\": \"Public\"\r\n },\r\n \"osType\": \"Linux\"\r\n },\r\n \"id\": \"/subscriptions/6987baff-3f62-48c9-a604-3432d813f7e6/resourceGroups/aci_rg7133/providers/Microsoft.ContainerInstance/containerGroups/acinetsdk3461\",\r\n \"name\": \"acinetsdk3461\",\r\n \"type\": \"Microsoft.ContainerInstance/containerGroups\",\r\n \"location\": \"westus\"\r\n}", | ||
| "ResponseHeaders": { | ||
| "Content-Length": [ | ||
| "582" | ||
| ], | ||
| "Content-Type": [ | ||
| "application/json; charset=utf-8" | ||
| ], | ||
| "Expires": [ | ||
| "-1" | ||
| ], | ||
| "Cache-Control": [ | ||
| "no-cache" | ||
| ], | ||
| "Date": [ | ||
| "Tue, 22 Aug 2017 20:50:55 GMT" | ||
| ], | ||
| "Pragma": [ | ||
| "no-cache" | ||
| ], | ||
| "x-ms-request-id": [ | ||
| "westus:d5c346f1-58e5-4c29-9a4c-e2306966df45" | ||
| ], | ||
| "x-ms-ratelimit-remaining-subscription-writes": [ | ||
| "1196" | ||
| ], | ||
| "x-ms-correlation-request-id": [ | ||
| "7e8ace92-15fa-4c79-ad1e-70abf48d92fc" | ||
| ], | ||
| "x-ms-routing-request-id": [ | ||
| "WESTUS:20170822T205055Z:7e8ace92-15fa-4c79-ad1e-70abf48d92fc" | ||
| ], | ||
| "Strict-Transport-Security": [ | ||
| "max-age=31536000; includeSubDomains" | ||
| ] | ||
| }, | ||
| "StatusCode": 201 | ||
| } | ||
| ], | ||
| "Names": { | ||
| "CreateResourceGroup": [ | ||
| "aci_rg7133" | ||
| ], | ||
| "ContainerInstanceCreateTest": [ | ||
| "acinetsdk3461" | ||
| ] | ||
| }, | ||
| "Variables": { | ||
| "SubscriptionId": "6987baff-3f62-48c9-a604-3432d813f7e6" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yolo3301 please remove this