|
1 | 1 | // Copyright (c) Microsoft Corporation.
|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
| 4 | +using Bicep.Core.FileSystem; |
4 | 5 | using Bicep.Core.UnitTests.Assertions;
|
5 | 6 | using Bicep.Core.UnitTests.Utils;
|
6 | 7 | using FluentAssertions;
|
| 8 | +using FluentAssertions.Execution; |
7 | 9 | using Microsoft.VisualStudio.TestTools.UnitTesting;
|
8 | 10 |
|
9 | 11 | namespace Bicep.Cli.IntegrationTests
|
@@ -187,5 +189,51 @@ param roleAssignmentName string
|
187 | 189 |
|
188 | 190 | """);
|
189 | 191 | }
|
| 192 | + |
| 193 | + [TestMethod] |
| 194 | + public async Task Test_Issue13785() |
| 195 | + { |
| 196 | + var paramFile = |
| 197 | + """ |
| 198 | + { |
| 199 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", |
| 200 | + "contentVersion": "1.0.0.0", |
| 201 | + "parameters": { |
| 202 | + "foo": { |
| 203 | + "value": "bar" |
| 204 | + } |
| 205 | + } |
| 206 | + } |
| 207 | + """; |
| 208 | + var expectedOutput = |
| 209 | + """ |
| 210 | + using '../main.bicep' |
| 211 | +
|
| 212 | + param foo = 'bar' |
| 213 | +
|
| 214 | + """; |
| 215 | + |
| 216 | + var (jsonPath, bicepparamPath) = Setup(TestContext, paramFile); |
| 217 | + Directory.SetCurrentDirectory(Path.GetDirectoryName(jsonPath)!); |
| 218 | + var (output, _, result) = await Bicep("decompile-params", jsonPath, "--bicep-file", "../main.bicep"); |
| 219 | + |
| 220 | + using (new AssertionScope()) |
| 221 | + { |
| 222 | + output.Should().BeEmpty(); |
| 223 | + result.Should().Be(0); |
| 224 | + File.ReadAllText(bicepparamPath).Should().BeEquivalentToIgnoringNewlines(expectedOutput); |
| 225 | + } |
| 226 | + } |
| 227 | + |
| 228 | + private static (string jsonPath, string bicepparamPath) Setup(TestContext context, string template, string? inputFile = null, string? outputDir = null) |
| 229 | + { |
| 230 | + var jsonPath = FileHelper.SaveResultFile(context, inputFile ?? "param.json", template); |
| 231 | + |
| 232 | + var bicepparamPath = outputDir is null |
| 233 | + ? PathHelper.GetDefaultDecompileparamOutputPath(jsonPath) |
| 234 | + : FileHelper.GetResultFilePath(context, outputDir); |
| 235 | + |
| 236 | + return (jsonPath, bicepparamPath); |
| 237 | + } |
190 | 238 | }
|
191 | 239 | }
|
0 commit comments