Skip to content
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

Fix Deployment Type Issue #26752 #26776

Merged
merged 4 commits into from
Nov 28, 2024
Merged
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
Expand Up @@ -40,6 +40,7 @@
using Microsoft.Azure.Management.Resources.Models;
using Microsoft.Rest.Azure;
using Microsoft.Rest.Azure.OData;
using Microsoft.Rest.Serialization;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using Newtonsoft.Json;
Expand Down Expand Up @@ -494,6 +495,18 @@ private TemplateValidationInfo GetTemplateValidationResult(PSDeploymentCmdletPar
return new TemplateValidationInfo(deploymentExtended.Properties?.Providers?.ToList() ?? new List<Provider>(), new List<ErrorDetail>(), deploymentExtended.Properties?.Diagnostics?.ToList() ?? new List<DeploymentDiagnosticsDefinition>());
case DeploymentValidationError deploymentValidationError:
return new TemplateValidationInfo(new List<Provider>(), new List<ErrorDetail>(deploymentValidationError.Error.AsArray()), new List<DeploymentDiagnosticsDefinition>());
case JObject obj:
// 202 Response is not deserialized in DeploymentsOperations so we should attempt to deserialize the object here before failing
// Should attempt to deserialize for success(DeploymentExtended)
try
{
var deploymentDeserialized = SafeJsonConvert.DeserializeObject<DeploymentExtended>(validationResult.ToString(), ResourceManagementClient.DeserializationSettings);
return new TemplateValidationInfo(deploymentDeserialized?.Properties?.Providers?.ToList() ?? new List<Provider>(), new List<ErrorDetail>(), deploymentDeserialized?.Properties?.Diagnostics?.ToList() ?? new List<DeploymentDiagnosticsDefinition>());
}
catch (Newtonsoft.Json.JsonException)
{
throw new InvalidOperationException($"Received unexpected type {validationResult.GetType()}");
}
default:
throw new InvalidOperationException($"Received unexpected type {validationResult.GetType()}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Moq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;

namespace Microsoft.Azure.Commands.Resources.Test.Models
Expand Down Expand Up @@ -329,6 +330,43 @@ public void TestTemplateShowsSuccessMessage()
progressLoggerMock.Verify(f => f("Template is valid."), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestTemplateShowsSuccessMessageWithObjectAsResponse()
{
Uri templateUri = new Uri("http://templateuri.microsoft.com");
Deployment deploymentFromValidate = new Deployment();
PSDeploymentCmdletParameters parameters = new PSDeploymentCmdletParameters()
{
ScopeType = DeploymentScopeType.ResourceGroup,
ResourceGroupName = resourceGroupName,
DeploymentMode = DeploymentMode.Incremental,
TemplateFile = templateFile,
};
resourceGroupMock.Setup(f => f.CheckExistenceWithHttpMessagesAsync(parameters.ResourceGroupName, null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() => CreateAzureOperationResponse(true)));

deploymentsMock.Setup(f => f.ValidateWithHttpMessagesAsync(resourceGroupName, It.IsAny<string>(), It.IsAny<Deployment>(), null, new CancellationToken()))
.Returns(Task.Factory.StartNew(() =>
{

var result = new AzureOperationResponse<object>()
{
Body = new JObject(new JProperty("id", "DeploymentId"))
};

result.Response = new System.Net.Http.HttpResponseMessage();
result.Response.StatusCode = HttpStatusCode.Accepted;

return result;
}))
.Callback((string rg, string dn, Deployment d, Dictionary<string, List<string>> customHeaders, CancellationToken c) => { deploymentFromValidate = d; });

TemplateValidationInfo error = resourcesClient.ValidateDeployment(parameters);
Assert.Empty(error.Errors);
progressLoggerMock.Verify(f => f("Template is valid."), Times.Once());
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestTemplateShowsSuccessMessageWithDiagnostics()
Expand Down
1 change: 1 addition & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

## Upcoming Release
* Added Diagnostics/Warnings to WhatIf/Validate results for deployments.
* Fixed bug unexpected type issue: [#26752]

## Version 7.7.0
* Updated Resources SDK to 2024-07-01.
Expand Down