Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ant/refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin authored Oct 11, 2022
2 parents 90ce3f6 + dc757b4 commit f99c42e
Show file tree
Hide file tree
Showing 63 changed files with 1,488 additions and 1,253 deletions.
16 changes: 16 additions & 0 deletions scripts/pr_install_vsix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# This script fetches the VSCode VSIX from the latest CI run for a given PR ID
# For now, it only works for PR branches within the repo (no forked PRs)
#
# Usage: ./scripts/pr_install_vsix.sh <pr_id>

usage="Usage: ./scripts/pr_install_vsix.sh <pr_id>"
prId=${1:?"Missing PR id. ${usage}"}

branch=$(gh pr view $prId --json headRefName --jq ".headRefName")
runId=$(gh run list -b $branch --limit 1 --json databaseId --jq ".[0].databaseId")

rm -Rf /tmp/bicep-vsix
gh run -R Azure/bicep download $runId -n vscode-bicep.vsix -D /tmp/bicep-vsix
code --install-extension /tmp/bicep-vsix/vscode-bicep.vsix
rm -Rf /tmp/bicep-vsix
238 changes: 110 additions & 128 deletions src/Bicep.Cli.E2eTests/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/Bicep.Cli.E2eTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"@types/minimist": "^1.2.2",
"@types/rimraf": "^3.0.2",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"eslint": "^8.24.0",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-jest": "^27.0.4",
"eslint-plugin-jest": "^27.1.1",
"eslint-plugin-prettier": "^4.2.1",
"jest": "^27.5.1",
"jest-runner-groups": "^2.2.0",
Expand Down
24 changes: 10 additions & 14 deletions src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ public async Task Build_Valid_SingleFile_ShouldSucceed(DataSet dataSet)
await dataSet.PublishModulesToRegistryAsync(clientFactory, TestContext);
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

var features = BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: dataSet.HasExternalModules);
var settings = new InvocationSettings(features, clientFactory, templateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);
var (output, error, result) = await Bicep(settings, "build", bicepFilePath);

using (new AssertionScope())
Expand All @@ -86,8 +85,9 @@ public async Task Build_Valid_SingleFile_ShouldSucceed(DataSet dataSet)
if (dataSet.HasExternalModules)
{
// ensure something got restored
Directory.Exists(settings.Features.CacheRootDirectory).Should().BeTrue();
Directory.EnumerateFiles(settings.Features.CacheRootDirectory, "*.json", SearchOption.AllDirectories).Should().NotBeEmpty();

Directory.Exists(settings.FeatureOverrides.CacheRootDirectory).Should().BeTrue();
Directory.EnumerateFiles(settings.FeatureOverrides.CacheRootDirectory!, "*.json", SearchOption.AllDirectories).Should().NotBeEmpty();
}

var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);
Expand All @@ -112,8 +112,7 @@ public async Task Build_Valid_SingleFile_ToStdOut_ShouldSucceed(DataSet dataSet)
await dataSet.PublishModulesToRegistryAsync(clientFactory, TestContext);
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

var features = BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: dataSet.HasExternalModules);
var settings = new InvocationSettings(features, clientFactory, templateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);

var (output, error, result) = await Bicep(settings, "build", "--stdout", bicepFilePath);

Expand All @@ -126,7 +125,7 @@ public async Task Build_Valid_SingleFile_ToStdOut_ShouldSucceed(DataSet dataSet)

if (dataSet.HasExternalModules)
{
settings.Features.Should().HaveValidModules();
settings.FeatureOverrides.Should().HaveValidModules();
}

var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);
Expand All @@ -151,8 +150,7 @@ public async Task Build_Valid_SingleFile_After_Restore_Should_Succeed(DataSet da
await dataSet.PublishModulesToRegistryAsync(clientFactory, TestContext);
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

var features = BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: dataSet.HasExternalModules);
var settings = new InvocationSettings(features, clientFactory, templateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);

var (restoreOutput, restoreError, restoreResult) = await Bicep(settings, "restore", bicepFilePath);
using (new AssertionScope())
Expand Down Expand Up @@ -191,8 +189,7 @@ public async Task Build_Valid_Params_File_Should_Succeed(BaselineData_Bicepparam
{
var data = baselineData.GetData(TestContext);

var features = BicepTestConstants.CreateFeatureProvider(TestContext, paramsFilesEnabled: true);
var settings = new InvocationSettings(features, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, ParamsFilesEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);

var (output, error, result) = await Bicep(settings, "build", data.Parameters.OutputFilePath);

Expand Down Expand Up @@ -220,7 +217,7 @@ public async Task Build_Valid_SingleFile_WithDigestReference_ShouldSucceed()

var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);

var tempDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
Directory.CreateDirectory(tempDirectory);
Expand Down Expand Up @@ -303,8 +300,7 @@ public async Task Build_Invalid_Single_Params_File_ShouldFail_WithExpectedErrorM
{
var data = baselineData.GetData(TestContext);

var features = BicepTestConstants.CreateFeatureProvider(TestContext, paramsFilesEnabled: true);
var settings = new InvocationSettings(features, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, ParamsFilesEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var diagnostics = GetAllParamDiagnostics(data.Parameters.OutputFilePath, BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);

var (output, error, result) = await Bicep(settings, "build", data.Parameters.OutputFilePath);
Expand Down
14 changes: 7 additions & 7 deletions src/Bicep.Cli.IntegrationTests/PublishCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task Publish_InvalidTarget_ShouldProduceExpectedError()
[TestMethod]
public async Task Publish_InvalidInputFile_ShouldProduceExpectedError()
{
var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var (output, error, result) = await Bicep(settings, "publish", "WrongFile.bicep", "--target", "br:example.azurecr.io/hello/there:v1");

result.Should().Be(1);
Expand All @@ -91,7 +91,7 @@ public async Task Publish_LocalTarget_ShouldProduceExpectedError()
[TestMethod]
public async Task Publish_OciDigestTarget_ShouldProduceExpectedError()
{
var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var (output, error, result) = await Bicep(settings, "publish", "WrongFile.bicep", "--target", "br:example.com/test@sha256:80f63ced0b80b63874c808a321f472755a3c9e93987d1fa0a51e13c65e4a52b9");

result.Should().Be(1);
Expand All @@ -118,7 +118,7 @@ public async Task Publish_ValidFile_ShouldSucceed(DataSet dataSet)
// mock client factory caches the clients
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository);

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory, templateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

var (output, error, result) = await Bicep(settings, "publish", bicepFilePath, "--target", $"br:{registryStr}/{repository}:v1");
result.Should().Be(0);
Expand Down Expand Up @@ -159,7 +159,7 @@ public async Task Publish_ValidArmTemplteFile_ShouldSucceed(DataSet dataSet)
// mock client factory caches the clients
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository);

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory, templateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

var (output, error, result) = await Bicep(settings, "publish", compiledFilePath, "--target", $"br:{registryStr}/{repository}:v1");
result.Should().Be(0);
Expand Down Expand Up @@ -201,7 +201,7 @@ public async Task Publish_RequestFailedException_ShouldFail()

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var (output, error, result) = await Bicep(settings, "publish", compiledFilePath, "--target", "br:fake/fake:v1");
using (new AssertionScope())
{
Expand Down Expand Up @@ -230,7 +230,7 @@ public async Task Publish_AggregateExceptionWithInnerRequestFailedExceptions_Sho

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var (output, error, result) = await Bicep(settings, "publish", compiledFilePath, "--target", "br:fake/fake:v1");
using (new AssertionScope())
{
Expand All @@ -248,7 +248,7 @@ public async Task Publish_InvalidFile_ShouldFail_WithExpectedErrorMessage(DataSe
var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

// publish won't actually happen, so broken client factory is fine
var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory);

var diagnostics = GetAllDiagnostics(bicepFilePath, settings.ClientFactory, settings.TemplateSpecRepositoryFactory);

Expand Down
16 changes: 8 additions & 8 deletions src/Bicep.Cli.IntegrationTests/RestoreCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public async Task Restore_ShouldSucceed(DataSet dataSet)

var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);
TestContext.WriteLine($"Cache root = {settings.Features.CacheRootDirectory}");
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);
TestContext.WriteLine($"Cache root = {settings.FeatureOverrides.CacheRootDirectory}");
var (output, error, result) = await Bicep(settings, "restore", bicepFilePath);

using (new AssertionScope())
Expand All @@ -71,7 +71,7 @@ public async Task Restore_ShouldSucceed(DataSet dataSet)
if (dataSet.HasExternalModules)
{
// ensure something got restored
settings.Features.Should().HaveValidModules();
settings.FeatureOverrides.Should().HaveValidModules();
}
}

Expand All @@ -89,7 +89,7 @@ public async Task Restore_ByDigest_ShouldSucceed()

var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, BicepTestConstants.TemplateSpecRepositoryFactory);

var tempDirectory = FileHelper.GetUniqueTestOutputPath(TestContext);
Directory.CreateDirectory(tempDirectory);
Expand Down Expand Up @@ -141,8 +141,8 @@ public async Task Restore_NonExistentModules_ShouldFail(DataSet dataSet)

var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain);

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);
TestContext.WriteLine($"Cache root = {settings.Features.CacheRootDirectory}");
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactory, templateSpecRepositoryFactory);
TestContext.WriteLine($"Cache root = {settings.FeatureOverrides.CacheRootDirectory}");
var (output, error, result) = await Bicep(settings, "restore", bicepFilePath);

using (new AssertionScope())
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task Restore_AggregateExceptionWithInnerRequestFailedExceptions_Sho

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var (output, error, result) = await Bicep(settings, "restore", compiledFilePath);
using(new AssertionScope())
{
Expand Down Expand Up @@ -207,7 +207,7 @@ public async Task Restore_RequestFailedException_ShouldFail()

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();

var settings = new InvocationSettings(BicepTestConstants.CreateFeatureProvider(TestContext, registryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory.Object, templateSpecRepositoryFactory.Object);
var (output, error, result) = await Bicep(settings, "restore", compiledFilePath);
using (new AssertionScope())
{
Expand Down
10 changes: 2 additions & 8 deletions src/Bicep.Cli.IntegrationTests/RootCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public async Task BicepVersionShouldPrintVersionInformation()
[TestMethod]
public async Task BicepHelpShouldPrintHelp()
{
var featuresMock = Repository.Create<IFeatureProvider>();
featuresMock.Setup(m => m.RegistryEnabled).Returns(true);

var settings = CreateDefaultSettings() with { Features = featuresMock.Object };
var settings = CreateDefaultSettings() with { FeatureOverrides = new(RegistryEnabled: true) };

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

Expand Down Expand Up @@ -132,10 +129,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 featuresMock = Repository.Create<IFeatureProvider>();
featuresMock.Setup(m => m.RegistryEnabled).Returns(false);

var settings = CreateDefaultSettings() with { Features = featuresMock.Object };
var settings = CreateDefaultSettings() with { FeatureOverrides = new(RegistryEnabled: false) };

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

Expand Down
7 changes: 4 additions & 3 deletions src/Bicep.Cli.IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Bicep.Core.Semantics;
using Bicep.Core.Text;
using Bicep.Core.UnitTests;
using Bicep.Core.UnitTests.Features;
using Bicep.Core.UnitTests.Utils;
using Bicep.Core.Workspaces;
using FluentAssertions;
Expand All @@ -28,12 +29,12 @@ public abstract class TestBase

protected static readonly MockRepository Repository = new(MockBehavior.Strict);

protected record InvocationSettings(IFeatureProvider Features, IContainerRegistryClientFactory ClientFactory, ITemplateSpecRepositoryFactory TemplateSpecRepositoryFactory);
protected record InvocationSettings(FeatureProviderOverrides FeatureOverrides, IContainerRegistryClientFactory ClientFactory, ITemplateSpecRepositoryFactory TemplateSpecRepositoryFactory);

protected static Task<(string output, string error, int result)> Bicep(params string[] args) => Bicep(CreateDefaultSettings(), args);

protected static InvocationSettings CreateDefaultSettings() => new(
Features: BicepTestConstants.Features,
FeatureOverrides: BicepTestConstants.FeatureOverrides,
ClientFactory: Repository.Create<IContainerRegistryClientFactory>().Object,
TemplateSpecRepositoryFactory: Repository.Create<ITemplateSpecRepositoryFactory>().Object);

Expand All @@ -43,7 +44,7 @@ protected record InvocationSettings(IFeatureProvider Features, IContainerRegistr
TestTypeHelper.CreateEmptyAzResourceTypeLoader(),
@out,
err,
featureProviderFactory: IFeatureProviderFactory.WithStaticFeatureProvider(settings.Features),
featureProviderFactory: BicepTestConstants.CreateFeatureProviderFactory(settings.FeatureOverrides),
clientFactory: settings.ClientFactory,
templateSpecRepositoryFactory: settings.TemplateSpecRepositoryFactory)).RunAsync(args));

Expand Down
Loading

0 comments on commit f99c42e

Please sign in to comment.