Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Jun 12, 2024
1 parent 1a990da commit 4678921
Show file tree
Hide file tree
Showing 84 changed files with 2,628 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="21.0.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bicep.Cli.UnitTests\Bicep.Cli.UnitTests.csproj" />
<ProjectReference Include="..\Bicep.Cli\Bicep.Cli.csproj" />
<ProjectReference Include="..\Bicep.Core.Samples\Bicep.Core.Samples.csproj" />
<ProjectReference Include="..\Bicep.Core.UnitTests\Bicep.Core.UnitTests.csproj" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public async Task Build_Invalid_SingleFile_ShouldFail_WithExpectedErrorMessage(D
{
var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext);
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);
var defaultSettings = CreateDefaultSettings();
var defaultSettings = new InvocationSettings();
var diagnostics = await GetAllDiagnostics(bicepFilePath, defaultSettings.ClientFactory, defaultSettings.TemplateSpecRepositoryFactory);

var (output, error, result) = await Bicep("build", bicepFilePath);
Expand All @@ -367,7 +367,7 @@ public async Task Build_Invalid_SingleFile_ToStdOut_ShouldFail_WithExpectedError
result.Should().Be(1);
output.Should().BeEmpty();

var defaultSettings = CreateDefaultSettings();
var defaultSettings = new InvocationSettings();
var diagnostics = await GetAllDiagnostics(bicepFilePath, defaultSettings.ClientFactory, defaultSettings.TemplateSpecRepositoryFactory);
error.Should().ContainAll(diagnostics);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace Bicep.Cli.IntegrationTests
public class BuildParamsCommandTests : TestBase
{
private InvocationSettings Settings
=> CreateDefaultSettings() with
=> new()
{
Environment = TestEnvironment.Create(
("stringEnvVariableName", "test"),
Expand Down
15 changes: 11 additions & 4 deletions src/Bicep.Cli.IntegrationTests/LintCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
using Microsoft.CodeAnalysis.Sarif;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.WindowsAzure.ResourceStack.Common.Json;
using Microsoft.Extensions.DependencyInjection;
using Moq;
using Bicep.Core.Registry.PublicRegistry;
using System.Collections.Immutable;
using System.Diagnostics;
using Bicep.Cli.UnitTests;
using FileSystem = System.IO.Abstractions.FileSystem;

namespace Bicep.Cli.IntegrationTests;

Expand Down Expand Up @@ -154,8 +160,8 @@ public async Task Lint_Invalid_SingleFile_ShouldFail_WithExpectedErrorMessage(Da
{
var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext);
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);
var defaultSettings = CreateDefaultSettings();
var diagnostics = await GetAllDiagnostics(bicepFilePath, defaultSettings.ClientFactory, defaultSettings.TemplateSpecRepositoryFactory);
var defaultSettings = new InvocationSettings();
var diagnostics = await GetAllDiagnostics(bicepFilePath, defaultSettings.ClientFactory, defaultSettings.TemplateSpecRepositoryFactory, defaultSettings.ModuleMetadataClient);

var (output, error, result) = await Bicep("lint", bicepFilePath);

Expand All @@ -173,8 +179,10 @@ public async Task Lint_WithEmptyBicepConfig_ShouldProduceConfigurationError()
string testOutputPath = FileHelper.GetUniqueTestOutputPath(TestContext);
var inputFile = FileHelper.SaveResultFile(TestContext, "main.bicep", DataSets.Empty.Bicep, testOutputPath);
var configurationPath = FileHelper.SaveResultFile(TestContext, "bicepconfig.json", string.Empty, testOutputPath);
var settings = new InvocationSettings() { ModuleMetadataClient = PublicRegistryModuleMetadataClientMock.CreateToThrow(new Exception("unit test failed: shouldn't call this")).Object };

var (output, error, result) = await Bicep(settings, "lint", inputFile);

var (output, error, result) = await Bicep("lint", inputFile);

result.Should().Be(1);
output.Should().BeEmpty();
Expand Down Expand Up @@ -254,7 +262,6 @@ public async Task Lint_with_sarif_diagnostics_format_should_output_valid_sarif()
sarifLog.Runs[0].Results[0].RuleId.Should().Be("no-unused-params");
sarifLog.Runs[0].Results[0].Message.Text.Should().Contain("is declared but never used");
}

private static IEnumerable<object[]> GetValidDataSetsWithoutWarnings() => DataSets
.AllDataSets
.Where(ds => ds.IsValid)
Expand Down
12 changes: 6 additions & 6 deletions src/Bicep.Cli.IntegrationTests/PublishProviderCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public async Task Publish_provider_should_fail_for_malformed_target()
var outputDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
var indexPath = Path.Combine(outputDirectory, "index.json");

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"asdf:123");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"asdf:123");
result.Should().Fail().And.HaveStderrMatch("*The specified module reference scheme \"asdf\" is not recognized.*");
}

Expand All @@ -132,7 +132,7 @@ public async Task Publish_provider_should_fail_for_missing_index_path()
var outputDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
var indexPath = Path.Combine(outputDirectory, "index.json");

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
result.Should().Fail().And.HaveStderrMatch("*Provider package creation failed: Could not find a part of the path '*'.*");
}

Expand All @@ -142,7 +142,7 @@ public async Task Publish_provider_should_fail_for_malformed_index()
var outputDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
var indexPath = FileHelper.SaveResultFile(TestContext, "index.json", "malformed", outputDirectory);

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
result.Should().Fail().And.HaveStderrMatch("*Provider package creation failed: 'm' is an invalid start of a value.*");
}

Expand All @@ -161,7 +161,7 @@ public async Task Publish_provider_should_fail_for_missing_referenced_types_json
}
""", outputDirectory);

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
result.Should().Fail().And.HaveStderrMatch("*Provider package creation failed: Could not find file '*types.json'.*");
}

Expand All @@ -181,7 +181,7 @@ public async Task Publish_provider_should_fail_for_malformed_types_json()
""", outputDirectory);
FileHelper.SaveResultFile(TestContext, "v1/types.json", "malformed", outputDirectory);

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
result.Should().Fail().And.HaveStderrMatch("*Provider package creation failed: 'm' is an invalid start of a value.*");
}

Expand Down Expand Up @@ -213,7 +213,7 @@ public async Task Publish_provider_should_fail_for_bad_type_location()
]
""", outputDirectory);

var result = await Bicep(CreateDefaultSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
var result = await Bicep(new InvocationSettings(), "publish-provider", indexPath, "--target", $"br:example.com/test/provider:0.0.1");
result.Should().Fail().And.HaveStderrMatch("*Provider package creation failed: Index was outside the bounds of the array.*");
}
}
4 changes: 2 additions & 2 deletions src/Bicep.Cli.IntegrationTests/RootCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task BicepVersionShouldPrintVersionInformation()
[TestMethod]
public async Task BicepHelpShouldPrintHelp()
{
var settings = CreateDefaultSettings() with { FeatureOverrides = new(RegistryEnabled: true) };
var settings = new InvocationSettings() { FeatureOverrides = new(RegistryEnabled: true) };

var (output, error, result) = await Bicep(settings, "--help");

Expand Down Expand Up @@ -127,7 +127,7 @@ public async Task BicepHelpShouldAlwaysIncludePublish()
{
// disable registry to ensure `bicep --help` is not consulting the feature provider before
// preparing the help text (as features can only be determined when an input file is specified)
var settings = CreateDefaultSettings() with { FeatureOverrides = new(RegistryEnabled: false) };
var settings = new InvocationSettings() with { FeatureOverrides = new(RegistryEnabled: false) };

var (output, error, result) = await Bicep(settings, "--help");

Expand Down
Loading

0 comments on commit 4678921

Please sign in to comment.