Skip to content

Commit d3c43fb

Browse files
work
1 parent bddc1b3 commit d3c43fb

File tree

61 files changed

+1820
-946
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1820
-946
lines changed

src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public async Task Build_Valid_SingleFile_WithTemplateSpecReference_ToStdOut_Shou
126126

127127
if (dataSet.HasExternalModules)
128128
{
129-
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
129+
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides!.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
130130
.And.AllSatisfy(m => m.Should().HaveSource());
131131
}
132132

@@ -194,7 +194,7 @@ public async Task Build_Valid_SingleFile_WithDigestReference_ShouldSucceed()
194194
var client = new MockRegistryBlobClient();
195195

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

199199
var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;
200200

src/Bicep.Cli.IntegrationTests/BuildParamsCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public async Task Build_bicepparam_should_fail_with_error_diagnostics_for_regist
492492

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

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

src/Bicep.Cli.IntegrationTests/LintCommandTests.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
using Bicep.Cli.UnitTests;
77
using Bicep.Core.Configuration;
88
using Bicep.Core.Registry;
9-
using Bicep.Core.Registry.PublicRegistry;
9+
using Bicep.Core.Registry.Indexing;
1010
using Bicep.Core.Samples;
1111
using Bicep.Core.UnitTests;
1212
using Bicep.Core.UnitTests.Mock;
13+
using Bicep.Core.UnitTests.Mock.Registry;
14+
using Bicep.Core.UnitTests.Mock.Registry.Indexing;
1315
using Bicep.Core.UnitTests.Registry;
1416
using Bicep.Core.UnitTests.Utils;
1517
using FluentAssertions;
@@ -112,7 +114,7 @@ public async Task Lint_Valid_SingleFile_WithDigestReference_ShouldSucceed()
112114
var client = new MockRegistryBlobClient();
113115

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

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

@@ -178,11 +180,10 @@ public async Task Lint_WithEmptyBicepConfig_ShouldProduceConfigurationError()
178180
string testOutputPath = FileHelper.GetUniqueTestOutputPath(TestContext);
179181
var inputFile = FileHelper.SaveResultFile(TestContext, "main.bicep", DataSets.Empty.Bicep, testOutputPath);
180182
var configurationPath = FileHelper.SaveResultFile(TestContext, "bicepconfig.json", string.Empty, testOutputPath);
181-
var settings = new InvocationSettings() { ModuleMetadataClient = PublicRegistryModuleIndexClientMock.CreateToThrow(new Exception("unit test failed: shouldn't call this")).Object };
183+
var settings = new InvocationSettings() { ModuleMetadataClient = PublicModuleIndexHttpClientMocks.Create([]).Object };
182184

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

185-
186187
result.Should().Be(1);
187188
output.Should().BeEmpty();
188189
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.");

src/Bicep.Cli.IntegrationTests/PublishCommandTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public async Task Publish_AllValidDataSets_ShouldSucceed(string testName, DataSe
162162
var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled);
163163

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

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

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

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

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

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

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

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

@@ -343,7 +343,7 @@ public async Task Publish_RequestFailedException_ShouldFail()
343343

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

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

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

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

src/Bicep.Cli.IntegrationTests/RestoreCommandTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task Restore_ShouldSucceed(string testName, DataSet dataSet, bool p
7171
if (dataSet.HasExternalModules)
7272
{
7373
// ensure something got restored
74-
CachedModules.GetCachedRegistryModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
74+
CachedModules.GetCachedModules(BicepTestConstants.FileSystem, settings.FeatureOverrides.CacheRootDirectory!).Should().HaveCountGreaterThan(0)
7575
.And.AllSatisfy(m => m.Should().HaveSource(publishSource));
7676
}
7777
}
@@ -90,7 +90,7 @@ public async Task Restore_should_succeed_for_bicepparam_file_with_registry_refer
9090
result.Should().Succeed().And.NotHaveStdout().And.NotHaveStderr();
9191

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

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

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

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

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

314314
var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;
315315

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

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

435435
var templateSpecRepositoryFactory = BicepTestConstants.TemplateSpecRepositoryFactory;
436436

@@ -517,7 +517,7 @@ public async Task Restore_AggregateExceptionWithInnerRequestFailedExceptions_Sho
517517

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

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

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

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

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

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

src/Bicep.Cli.IntegrationTests/TestBase.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
using Bicep.Core.Extensions;
88
using Bicep.Core.FileSystem;
99
using Bicep.Core.Registry;
10-
using Bicep.Core.Registry.PublicRegistry;
10+
using Bicep.Core.Registry.Indexing;
11+
using Bicep.Core.Registry.Indexing.HttpClients;
1112
using Bicep.Core.Text;
1213
using Bicep.Core.UnitTests;
1314
using Bicep.Core.UnitTests.Features;
@@ -23,14 +24,14 @@ namespace Bicep.Cli.IntegrationTests
2324
{
2425
public abstract class TestBase : Bicep.Core.UnitTests.TestBase
2526
{
26-
private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicRegistryModuleIndexClient? moduleMetadataClient)
27+
private static BicepCompiler CreateCompiler(IContainerRegistryClientFactory clientFactory, ITemplateSpecRepositoryFactory templateSpecRepositoryFactory, IPublicModuleIndexHttpClient? moduleMetadataClient)
2728
=> ServiceBuilder.Create(
2829
services =>
2930
{
3031
services
3132
.AddSingleton(clientFactory)
3233
.AddSingleton(templateSpecRepositoryFactory)
33-
.AddSingleton<IPublicRegistryModuleMetadataProvider, PublicRegistryModuleMetadataProvider>();
34+
.AddRegistryIndexerServices();
3435

3536
IServiceCollectionExtensions.AddMockHttpClientIfNotNull(services, moduleMetadataClient);
3637
}
@@ -49,21 +50,21 @@ protected record InvocationSettings
4950
public IContainerRegistryClientFactory ClientFactory { get; init; }
5051
public ITemplateSpecRepositoryFactory TemplateSpecRepositoryFactory { get; init; }
5152
public IEnvironment? Environment { get; init; }
52-
public IPublicRegistryModuleIndexClient ModuleMetadataClient { get; init; }
53+
public IPublicModuleIndexHttpClient ModuleMetadataClient { get; init; }
5354

5455
public InvocationSettings(
5556
FeatureProviderOverrides? FeatureOverrides = null,
5657
IContainerRegistryClientFactory? ClientFactory = null,
5758
ITemplateSpecRepositoryFactory? TemplateSpecRepositoryFactory = null,
5859
IEnvironment? Environment = null,
59-
IPublicRegistryModuleIndexClient? ModuleMetadataClient = null)
60+
IPublicModuleIndexHttpClient? ModuleMetadataClient = null)
6061
{
6162
this.FeatureOverrides = FeatureOverrides;
6263
this.ClientFactory = ClientFactory ?? Repository.Create<IContainerRegistryClientFactory>().Object;
6364
this.TemplateSpecRepositoryFactory = TemplateSpecRepositoryFactory ?? Repository.Create<ITemplateSpecRepositoryFactory>().Object;
6465
this.Environment = Environment;
6566

66-
this.ModuleMetadataClient = ModuleMetadataClient ?? StrictMock.Of<IPublicRegistryModuleIndexClient>().Object;
67+
this.ModuleMetadataClient = ModuleMetadataClient ?? StrictMock.Of<IPublicModuleIndexHttpClient>().Object;
6768
}
6869
}
6970

@@ -109,7 +110,7 @@ protected static void AssertNoErrors(string error)
109110
}
110111
}
111112

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

0 commit comments

Comments
 (0)