Skip to content

Commit

Permalink
works
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenWeatherford committed Jan 16, 2025
1 parent 42dbe3e commit 479ed50
Show file tree
Hide file tree
Showing 102 changed files with 3,702 additions and 1,799 deletions.
4 changes: 2 additions & 2 deletions src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task Build_Valid_SingleFile_WithTemplateSpecReference_ToStdOut_Shou

if (dataSet.HasExternalModules)
{
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
.And.AllSatisfy(m => m.Should().HaveSource());
}

Expand Down Expand Up @@ -194,7 +194,7 @@ public async Task Build_Valid_SingleFile_WithDigestReference_ShouldSucceed()
var client = new MockRegistryBlobClient();

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), registryUri, repository)).Returns(client);
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), registryUri, repository)).Returns(client);

var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;

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 @@ -492,7 +492,7 @@ public async Task Build_bicepparam_should_fail_with_error_diagnostics_for_regist

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://mockregistry.io"), "parameters/basic"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://mockregistry.io"), "parameters/basic"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down
9 changes: 5 additions & 4 deletions src/Bicep.Cli.IntegrationTests/LintCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
using Bicep.Cli.UnitTests;
using Bicep.Core.Configuration;
using Bicep.Core.Registry;
using Bicep.Core.Registry.PublicRegistry;
using Bicep.Core.Registry.Indexing;
using Bicep.Core.Samples;
using Bicep.Core.UnitTests;
using Bicep.Core.UnitTests.Mock;
using Bicep.Core.UnitTests.Mock.Registry;
using Bicep.Core.UnitTests.Mock.Registry.Indexing;
using Bicep.Core.UnitTests.Registry;
using Bicep.Core.UnitTests.Utils;
using FluentAssertions;
Expand Down Expand Up @@ -112,7 +114,7 @@ public async Task Lint_Valid_SingleFile_WithDigestReference_ShouldSucceed()
var client = new MockRegistryBlobClient();

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), registryUri, repository)).Returns(client);
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), registryUri, repository)).Returns(client);

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

Expand Down Expand Up @@ -178,11 +180,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 = PublicRegistryModuleIndexClientMock.CreateToThrow(new Exception("unit test failed: shouldn't call this")).Object };
var settings = new InvocationSettings() { ModuleMetadataClient = PublicModuleIndexHttpClientMocks.Create([]).Object };

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


result.Should().Be(1);
output.Should().BeEmpty();
error.Should().StartWith($"{inputFile}(1,1) : Error BCP271: Failed to parse the contents of the Bicep configuration file \"{configurationPath}\" as valid JSON: The input does not contain any JSON tokens. Expected the input to start with a valid JSON token, when isFinalBlock is true. LineNumber: 0 | BytePositionInLine: 0.");
Expand Down
10 changes: 5 additions & 5 deletions src/Bicep.Cli.IntegrationTests/PublishCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public async Task Publish_AllValidDataSets_ShouldSucceed(string testName, DataSe
var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);

// mock client factory caches the clients
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository);
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration.Cloud, registryUri, repository);

var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

Expand Down Expand Up @@ -261,7 +261,7 @@ public async Task Publish_ValidArmTemplateFile_AllValidDataSets_ShouldSucceed(Da
var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);

// mock client factory caches the clients
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository);
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration.Cloud, registryUri, repository);

var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

Expand Down Expand Up @@ -315,7 +315,7 @@ public async Task Publish_ValidArmTemplateFile_WithSource_ShouldFail()
var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);

// mock client factory caches the clients
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository);
var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration.Cloud, registryUri, repository);

var settings = new InvocationSettings(new(TestContext, RegistryEnabled: true), clientFactory, templateSpecRepositoryFactory);

Expand Down Expand Up @@ -343,7 +343,7 @@ public async Task Publish_RequestFailedException_ShouldFail()

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://fake"), "fake"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://fake"), "fake"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down Expand Up @@ -375,7 +375,7 @@ public async Task Publish_AggregateExceptionWithInnerRequestFailedExceptions_Sho

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://fake"), "fake"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://fake"), "fake"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down
22 changes: 11 additions & 11 deletions src/Bicep.Cli.IntegrationTests/RestoreCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public async Task Restore_ShouldSucceed(string testName, DataSet dataSet, bool p
if (dataSet.HasExternalModules)
{
// ensure something got restored
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
.And.AllSatisfy(m => m.Should().HaveSource(publishSource));
}
}
Expand All @@ -90,7 +90,7 @@ public async Task Restore_should_succeed_for_bicepparam_file_with_registry_refer
result.Should().Succeed().And.NotHaveStdout().And.NotHaveStderr();

// ensure something got restored
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
.And.AllSatisfy(m => m.Should().NotHaveSource());
}

Expand All @@ -117,13 +117,13 @@ public async Task Restore_ShouldSucceedWithAnonymousClient(string testName, Data
// this will force fallback to the anonymous client
var clientFactoryForRestore = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactoryForRestore
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), It.IsAny<Uri>(), It.IsAny<string>()))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), It.IsAny<Uri>(), It.IsAny<string>()))
.Returns(clientWithCredentialUnavailable.Object);

// anonymous client creation will redirect to the working client factory containing mock published modules
clientFactoryForRestore
.Setup(m => m.CreateAnonymousBlobClient(It.IsAny<RootConfiguration>(), It.IsAny<Uri>(), It.IsAny<string>()))
.Returns<RootConfiguration, Uri, string>(clientFactory.CreateAnonymousBlobClient);
.Setup(m => m.CreateAnonymousBlobClient(It.IsAny<CloudConfiguration>(), It.IsAny<Uri>(), It.IsAny<string>()))
.Returns<CloudConfiguration, Uri, string>(clientFactory.CreateAnonymousBlobClient);

var settings = new InvocationSettings(new(TestContext, RegistryEnabled: dataSet.HasExternalModules), clientFactoryForRestore.Object, templateSpecRepositoryFactory);
TestContext.WriteLine($"Cache root = {settings.FeatureOverrides!.CacheRootDirectory}");
Expand All @@ -139,7 +139,7 @@ public async Task Restore_ShouldSucceedWithAnonymousClient(string testName, Data
if (dataSet.HasExternalModules)
{
// ensure something got restored
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
.And.AllSatisfy(m => m.Should().HaveSource(publishSource));
}
}
Expand Down Expand Up @@ -309,7 +309,7 @@ public async Task Restore_With_Force_Should_Overwrite_Existing_Cache(bool publis
var client = new MockRegistryBlobClient();

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), registryUri, repository)).Returns(client);
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), registryUri, repository)).Returns(client);

var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;

Expand Down Expand Up @@ -430,7 +430,7 @@ public async Task Restore_ByDigest_ShouldSucceed(bool publishSource)
var client = new MockRegistryBlobClient();

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), registryUri, repository)).Returns(client);
clientFactory.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), registryUri, repository)).Returns(client);

var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;

Expand Down Expand Up @@ -517,7 +517,7 @@ public async Task Restore_AggregateExceptionWithInnerRequestFailedExceptions_Sho

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://fake"), "fake"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://fake"), "fake"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down Expand Up @@ -549,7 +549,7 @@ public async Task Restore_RequestFailedException_ShouldFail()

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://fake"), "fake"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://fake"), "fake"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down Expand Up @@ -578,7 +578,7 @@ public async Task Restore_bicepparam_should_fail_with_error_diagnostics_for_regi

var clientFactory = StrictMock.Of<IContainerRegistryClientFactory>();
clientFactory
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<RootConfiguration>(), new Uri("https://mockregistry.io"), "parameters/basic"))
.Setup(m => m.CreateAuthenticatedBlobClient(It.IsAny<CloudConfiguration>(), new Uri("https://mockregistry.io"), "parameters/basic"))
.Returns(client.Object);

var templateSpecRepositoryFactory = StrictMock.Of<ITemplateSpecRepositoryFactory>();
Expand Down
15 changes: 8 additions & 7 deletions src/Bicep.Cli.IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
using Bicep.Core.Extensions;
using Bicep.Core.FileSystem;
using Bicep.Core.Registry;
using Bicep.Core.Registry.PublicRegistry;
using Bicep.Core.Registry.Indexing;
using Bicep.Core.Registry.Indexing.HttpClients;
using Bicep.Core.Text;
using Bicep.Core.UnitTests;
using Bicep.Core.UnitTests.Features;
Expand All @@ -23,14 +24,14 @@ namespace Bicep.Cli.IntegrationTests
{
public abstract class TestBase : Bicep.Core.UnitTests.TestBase
{
private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicRegistryModuleIndexClient? moduleMetadataClient)
private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicModuleIndexHttpClient? moduleMetadataClient)
=> ServiceBuilder.Create(
services =>
{
services
.AddSingleton(clientFactory)
.AddSingleton(templateSpecRepositoryFactory)
.AddSingleton<IPublicRegistryModuleMetadataProvider, PublicRegistryModuleMetadataProvider>();
.AddRegistryIndexerServices();

IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, moduleMetadataClient);
}
Expand All @@ -49,21 +50,21 @@ protected record InvocationSettings
public IContainerRegistryClientFactory ClientFactory { get; init; }
public ITemplateSpecRepositoryFactory TemplateSpecRepositoryFactory { get; init; }
public IEnvironment? Environment { get; init; }
public IPublicRegistryModuleIndexClient ModuleMetadataClient { get; init; }
public IPublicModuleIndexHttpClient ModuleMetadataClient { get; init; }

public InvocationSettings(
FeatureProviderOverrides? FeatureOverrides = null,
IContainerRegistryClientFactory? ClientFactory = null,
ITemplateSpecRepositoryFactory? TemplateSpecRepositoryFactory = null,
IEnvironment? Environment = null,
IPublicRegistryModuleIndexClient? ModuleMetadataClient = null)
IPublicModuleIndexHttpClient? ModuleMetadataClient = null)
{
this.FeatureOverrides = FeatureOverrides;
this.ClientFactory = ClientFactory ?? Repository.Create<IContainerRegistryClientFactory>().Object;
this.TemplateSpecRepositoryFactory = TemplateSpecRepositoryFactory ?? Repository.Create<ITemplateSpecRepositoryFactory>().Object;
this.Environment = Environment;

this.ModuleMetadataClient = ModuleMetadataClient ?? StrictMock.Of<IPublicRegistryModuleIndexClient>().Object;
this.ModuleMetadataClient = ModuleMetadataClient ?? StrictMock.Of<IPublicModuleIndexHttpClient>().Object;
}
}

Expand Down Expand Up @@ -109,7 +110,7 @@ protected static void AssertNoErrors(string error)
}
}

protected static async Task<IEnumerable<string>> GetAllDiagnostics(string bicepFilePath, IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicRegistryModuleIndexClient? moduleMetadataClient = null)
protected static async Task<IEnumerable<string>> GetAllDiagnostics(string bicepFilePath, IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicModuleIndexHttpClient? moduleMetadataClient = null)
{
var compilation = await CreateCompiler(clientFactory, templateSpecRepositoryFactory, moduleMetadataClient).CreateCompilation(PathHelper.FilePathToFileUrl(bicepFilePath));

Expand Down
Loading

0 comments on commit 479ed50

Please sign in to comment.