Skip to content

Commit

Permalink
Correct other minor bugs relating to new provider syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Mar 7, 2024
1 parent 09afb76 commit 9d7f637
Show file tree
Hide file tree
Showing 16 changed files with 81 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/ExamplesTests.cs
Expand Up @@ -39,7 +39,7 @@ private async Task RunExampleTest(EmbeddedFile embeddedBicep, FeatureProviderOve
{
DiagnosticAssertions.DoWithDiagnosticAnnotations(
file,
diagnostics.Where(d => !IsPermittedMissingTypeDiagnostic(d)).Where(d => !d.Code.Equals("BCP395")),
diagnostics.Where(d => !IsPermittedMissingTypeDiagnostic(d)),
diagnostics =>
{
diagnostics.Should().BeEmpty("{0} should not have warnings or errors", file.FileUri.LocalPath);
Expand Down
26 changes: 13 additions & 13 deletions src/Bicep.Core.IntegrationTests/ExtensibilityTests.cs
Expand Up @@ -213,7 +213,7 @@ public void Foo_import_existing_requires_uniqueName()
public void Kubernetes_import_existing_warns_with_readonly_fields()
{
var result = CompilationHelper.Compile(Services, """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -232,7 +232,7 @@ public void Kubernetes_import_existing_warns_with_readonly_fields()
""");

result.Should().GenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("no-unused-existing-resources", DiagnosticLevel.Warning, "Existing resource \"service\" is declared but never used."),
("BCP073", DiagnosticLevel.Warning, "The property \"labels\" is read-only. Expressions cannot be assigned to read-only properties. If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
("BCP073", DiagnosticLevel.Warning, "The property \"annotations\" is read-only. Expressions cannot be assigned to read-only properties. If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
Expand All @@ -243,19 +243,19 @@ public void Kubernetes_import_existing_warns_with_readonly_fields()
public void Kubernetes_competing_imports_are_blocked()
{
var result = CompilationHelper.Compile(Services, @"
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
");

result.Should().NotGenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP028", DiagnosticLevel.Error, "Identifier \"kubernetes\" is declared multiple times. Remove or rename the duplicates."),
("BCP207", DiagnosticLevel.Error, "Namespace \"kubernetes\" is declared multiple times. Remove the duplicates."),
("BCP028", DiagnosticLevel.Error, "Identifier \"kubernetes\" is declared multiple times. Remove or rename the duplicates."),
Expand All @@ -267,7 +267,7 @@ public void Kubernetes_competing_imports_are_blocked()
public void Kubernetes_import_existing_resources()
{
var result = CompilationHelper.Compile(Services, @"
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -292,7 +292,7 @@ public void Kubernetes_import_existing_resources()
");

result.Should().GenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("no-unused-existing-resources", DiagnosticLevel.Warning, "Existing resource \"service\" is declared but never used."),
("no-unused-existing-resources", DiagnosticLevel.Warning, "Existing resource \"secret\" is declared but never used."),
("no-unused-existing-resources", DiagnosticLevel.Warning, "Existing resource \"configmap\" is declared but never used."),
Expand All @@ -303,7 +303,7 @@ public void Kubernetes_import_existing_resources()
public void Kubernetes_import_existing_connectionstring_test()
{
var result = CompilationHelper.Compile(Services, @"
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down Expand Up @@ -334,14 +334,14 @@ public void Kubernetes_import_existing_connectionstring_test()
");

result.Should().GenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().NotHaveAnyDiagnostics();
result.Should().NotHaveAnyDiagnostics();
}

[TestMethod]
public void Kubernetes_CustomResourceType_EmitWarning()
{
var result = CompilationHelper.Compile(Services, """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -353,7 +353,7 @@ public void Kubernetes_CustomResourceType_EmitWarning()
""");

result.Should().GenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP081", DiagnosticLevel.Warning, @"Resource type ""custom/Foo@v1"" does not have types available."),
});
}
Expand All @@ -362,7 +362,7 @@ public void Kubernetes_CustomResourceType_EmitWarning()
public void Kubernetes_AmbiguousFallbackType_MustFullyQualify()
{
var result = CompilationHelper.Compile(Services, """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand All @@ -384,7 +384,7 @@ public void Kubernetes_AmbiguousFallbackType_MustFullyQualify()
""");

result.Should().NotGenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP264", DiagnosticLevel.Error, @"Resource type ""Microsoft.Compute/availabilitySets@2023-01-01"" is declared in multiple imported namespaces (""az"", ""kubernetes""), and must be fully-qualified."),
("BCP035", DiagnosticLevel.Error, @"The specified ""resource"" declaration is missing the following required properties: ""name""."),
("BCP081", DiagnosticLevel.Warning, @"Resource type ""Microsoft.Compute/availabilitySets@2023-01-01"" does not have types available."),
Expand Down
70 changes: 34 additions & 36 deletions src/Bicep.Core.IntegrationTests/ProviderImportTests.cs
Expand Up @@ -72,13 +72,13 @@ public ResultWithDiagnostic<NamespaceType> TryGetNamespace(ResourceTypesProvider
}

[TestMethod]
public async Task Imports_are_disabled_unless_feature_is_enabled()
public async Task Providers_are_disabled_unless_feature_is_enabled()
{
var services = new ServiceBuilder();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'az@1.0.0'
provider az
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP203", DiagnosticLevel.Error, "Using provider statements requires enabling EXPERIMENTAL feature \"Extensibility\"."),
// BCP084 is raised because BCP203 prevented the compiler from binding a namespace to the `az` symbol (an ErrorType was bound instead).
("BCP084", DiagnosticLevel.Error, "The symbolic name \"az\" is reserved. Please use a different symbolic name. Reserved namespaces are \"az\", \"sys\"."),
Expand Down Expand Up @@ -106,9 +106,9 @@ public async Task Provider_Statement_With_Invalid_Keyword_Should_Emit_Diagnostic
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'sys@1.0.0' blahblah
provider sys blahblah
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP305", DiagnosticLevel.Error, "Expected the \"with\" keyword, \"as\" keyword, or a new line character at this location."),
});
}
Expand All @@ -118,9 +118,9 @@ public async Task Provider_Statement_Without_Brace_Should_Raise_Error()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'kubernetes@1.0.0' with
provider kubernetes with
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP018", DiagnosticLevel.Error, "Expected the \"{\" character at this location."),
});
}
Expand All @@ -130,12 +130,12 @@ public async Task Provider_Statement_Without_As_Keyword_Should_Raise_Error()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
kubeConfig: 'foo'
namespace: 'bar'
} something
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP012", DiagnosticLevel.Error, "Expected the \"as\" keyword at this location."),
});
}
Expand All @@ -145,12 +145,12 @@ public async Task Provider_Statement_Without_Alias_Name_Should_Raise_Error()
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
kubeConfig: 'foo'
namespace: 'bar'
} as
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP202", DiagnosticLevel.Error, "Expected a provider alias name at this location."),
});
}
Expand All @@ -160,9 +160,9 @@ public async Task Provider_Statement_Without_Alias_Name_For_Sys_Should_Raise_Err
{
var services = await GetServices();
var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'sys@1.0.0' as
provider sys as
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP202", DiagnosticLevel.Error, "Expected a provider alias name at this location."),
});
}
Expand All @@ -178,13 +178,11 @@ public async Task Using_import_instead_of_provider_raises_warning()
});
}

[DataRow("az")]
[DataRow("sys")]
[TestMethod]
public async Task Using_legacy_import_syntax_raises_warning_for_az_provider(string providerName)
public async Task Using_legacy_import_syntax_raises_warning_for_az_provider()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), $"""
provider '{providerName}@1.0.0' as {providerName}
provider 'az@1.0.0' as az
""");

result.Should().HaveDiagnostics(new[] {
Expand All @@ -196,11 +194,11 @@ public async Task Using_legacy_import_syntax_raises_warning_for_az_provider(stri
public async Task Import_configuration_is_blocked_by_default()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0' with {
provider az with {
foo: 'bar'
}
""");
result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP205", DiagnosticLevel.Error, "Provider namespace \"az\" does not support configuration."),
});
}
Expand All @@ -220,7 +218,7 @@ public async Task Imports_return_error_with_unrecognized_namespace()
public async Task Using_import_statements_frees_up_the_namespace_symbol()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0' as newAz
provider az as newAz

var az = 'Fake AZ!'
var myRg = newAz.resourceGroup()
Expand All @@ -229,15 +227,15 @@ public async Task Using_import_statements_frees_up_the_namespace_symbol()
output rgLocation string = myRg.location
""");

result.ExcludingDiagnostics("BCP395").Should().NotHaveAnyDiagnostics();
result.Should().NotHaveAnyDiagnostics();
}

[TestMethod]
public async Task You_can_swap_imported_namespaces_if_you_really_really_want_to()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0' as sys
provider 'sys@1.0.0' as az
provider az as sys
provider sys as az

var myRg = sys.resourceGroup()

Expand All @@ -246,15 +244,15 @@ public async Task You_can_swap_imported_namespaces_if_you_really_really_want_to(
""");

result.Should().GenerateATemplate();
result.ExcludingDiagnostics("BCP395").Should().NotHaveAnyDiagnostics();
result.Should().NotHaveAnyDiagnostics();
result.Template.Should().HaveValueAtPath("$.outputs.rgLocation.metadata.description", "why on earth would you do this?");
}

[TestMethod]
public async Task Overwriting_single_built_in_namespace_with_import_is_prohibited()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0' as sys
provider az as sys

var myRg = sys.resourceGroup()

Expand All @@ -268,14 +266,14 @@ public async Task Overwriting_single_built_in_namespace_with_import_is_prohibite
public async Task Singleton_imports_cannot_be_used_multiple_times()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0' as az1
provider 'az@1.0.0' as az2
provider az as az1
provider az as az2

provider 'sys@1.0.0' as sys1
provider 'sys@1.0.0' as sys2
provider sys as sys1
provider sys as sys2
""");

result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP207", DiagnosticLevel.Error, "Namespace \"az\" is declared multiple times. Remove the duplicates."),
("BCP207", DiagnosticLevel.Error, "Namespace \"az\" is declared multiple times. Remove the duplicates."),
("BCP207", DiagnosticLevel.Error, "Namespace \"sys\" is declared multiple times. Remove the duplicates."),
Expand All @@ -287,14 +285,14 @@ public async Task Singleton_imports_cannot_be_used_multiple_times()
public async Task Import_names_must_not_conflict_with_other_symbols()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), """
provider 'az@1.0.0'
provider 'kubernetes@1.0.0' with {
provider az
provider kubernetes with {
kubeConfig: ''
namespace: ''
} as az
""");

result.ExcludingDiagnostics("BCP395").Should().HaveDiagnostics(new[] {
result.Should().HaveDiagnostics(new[] {
("BCP028", DiagnosticLevel.Error, "Identifier \"az\" is declared multiple times. Remove or rename the duplicates."),
("BCP028", DiagnosticLevel.Error, "Identifier \"az\" is declared multiple times. Remove or rename the duplicates."),
});
Expand Down Expand Up @@ -409,7 +407,7 @@ public async Task Config_with_optional_properties_can_be_skipped()
[TestMethod]
public async Task MicrosoftGraph_imports_succeed_with_preview_feature_enabled()
{
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), @"provider 'microsoftGraph@1.0.0' as graph");
var result = await CompilationHelper.RestoreAndCompile(await GetServices(), @"provider microsoftGraph as graph");

result.Should().HaveDiagnostics(new[] {
("BCP204", DiagnosticLevel.Error, "Provider namespace \"microsoftGraph\" is not recognized."),
Expand All @@ -418,9 +416,9 @@ public async Task MicrosoftGraph_imports_succeed_with_preview_feature_enabled()
var serviceWithPreview = new ServiceBuilder()
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, MicrosoftGraphPreviewEnabled: true));

result = await CompilationHelper.RestoreAndCompile(serviceWithPreview, @"provider 'microsoftGraph@1.0.0' as graph");
result = await CompilationHelper.RestoreAndCompile(serviceWithPreview, @"provider microsoftGraph as graph");

result.ExcludingDiagnostics("BCP395").Should().NotHaveAnyDiagnostics();
result.Should().NotHaveAnyDiagnostics();
}
}
}
4 changes: 2 additions & 2 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Expand Up @@ -5683,7 +5683,7 @@ public void Test_Issue12347()
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true))
.WithConfigurationPatch(x => x.WithAnalyzers(x.Analyzers.SetValue("core.rules.use-recent-api-versions.level", "error"))),
("main.bicep", """
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
kubeConfig: 'config'
namespace: ''
} as k8s
Expand Down Expand Up @@ -5721,7 +5721,7 @@ public void Test_Issue12347()
}
"""));

result.ExcludingLinterDiagnostics().ExcludingDiagnostics("BCP395").Should().NotHaveAnyDiagnostics();
result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
}

// https://github.com/Azure/bicep/issues/13250
Expand Down
@@ -1,7 +1,7 @@
@secure()
param kubeConfig string

provider 'kubernetes@1.0.0' with {
provider kubernetes with {
kubeConfig: kubeConfig
namespace: 'default'
}
Expand Down
@@ -1,4 +1,4 @@
provider 'microsoftGraph@1.0.0' as graph
provider microsoftGraph as graph

param appRoleId string = 'bc76c90e-eb7f-4a29-943b-49e88762d09d'
param scopeId string = 'f761933c-643b-424f-a169-f9313d23a913'
Expand Down
@@ -1,4 +1,4 @@
provider 'microsoftGraph@1.0.0'
provider microsoftGraph

resource resourceApp 'Microsoft.Graph/applications@beta' existing = {
uniqueName: 'resourceApp'
Expand Down
Expand Up @@ -1891,7 +1891,7 @@ public void ProvidesFixWithMostRecentVersion_CustomAgeZero()
public void LinterIgnoresNotAzureResources()
{
CompileAndTestWithFakeDateAndTypes(@"
provider 'kubernetes@1.0.0' with {
provider kubernetes with {
namespace: 'default'
kubeConfig: ''
}
Expand Down

0 comments on commit 9d7f637

Please sign in to comment.