forked from Azure/bicep
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to simplify logic for 3rd party provider implementation (Azu…
…re#12754) ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/12754)
- Loading branch information
1 parent
fef5764
commit 5c0d0fe
Showing
43 changed files
with
4,418 additions
and
4,577 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
using System; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.IO; | ||
using System.IO.Abstractions.TestingHelpers; | ||
using System.Threading.Tasks; | ||
using Azure.Bicep.Types.Az; | ||
using Bicep.Core.Diagnostics; | ||
using Bicep.Core.IntegrationTests.Extensibility; | ||
using Bicep.Core.Registry; | ||
using Bicep.Core.Samples; | ||
using Bicep.Core.Semantics.Namespaces; | ||
using Bicep.Core.TypeSystem.Providers; | ||
using Bicep.Core.TypeSystem.Providers.Az; | ||
using Bicep.Core.UnitTests; | ||
using Bicep.Core.UnitTests.Assertions; | ||
using Bicep.Core.UnitTests.FileSystem; | ||
using Bicep.Core.UnitTests.Utils; | ||
using FluentAssertions; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace Bicep.Core.IntegrationTests | ||
{ | ||
[TestClass] | ||
public class DynamicAzTypesTests : TestBase | ||
{ | ||
private static readonly Lazy<IResourceTypeLoader> azTypeLoaderLazy = new(() => new AzResourceTypeLoader(new AzTypeLoader())); | ||
|
||
private async Task<ServiceBuilder> GetServices() | ||
{ | ||
var indexJson = FileHelper.SaveResultFile(TestContext, "types/index.json", """{"Resources": {}, "Functions": {}}"""); | ||
var clientFactory = await DataSetsExtensions.GetClientFactoryWithAzModulePublished(new System.IO.Abstractions.FileSystem(), indexJson); | ||
|
||
var cacheRoot = FileHelper.GetUniqueTestOutputPath(TestContext); | ||
Directory.CreateDirectory(cacheRoot); | ||
|
||
return new ServiceBuilder() | ||
.WithFeatureOverrides(new(ExtensibilityEnabled: true, DynamicTypeLoadingEnabled: true, CacheRootDirectory: cacheRoot)) | ||
.WithContainerRegistryClientFactory(clientFactory) | ||
.WithAzResourceTypeLoader(azTypeLoaderLazy.Value); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Az_namespace_can_be_used_without_configuration() | ||
{ | ||
var services = await GetServices(); | ||
var result = await CompilationHelper.RestoreAndCompile(services, ("main.bicep", @$" | ||
provider 'br/public:az@{BicepTestConstants.BuiltinAzProviderVersion}' | ||
")); | ||
|
||
result.Should().GenerateATemplate(); | ||
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics(); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Az_namespace_errors_with_configuration() | ||
{ | ||
var services = await GetServices(); | ||
var result = await CompilationHelper.RestoreAndCompile(services, @$" | ||
provider 'br/public:az@{BicepTestConstants.BuiltinAzProviderVersion}' with {{}} | ||
"); | ||
|
||
result.Should().NotGenerateATemplate(); | ||
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] { | ||
("BCP205", DiagnosticLevel.Error, "Provider namespace \"az\" does not support configuration."), | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.