Skip to content

Commit

Permalink
Merge branch 'Azure:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
geekswagg committed Apr 1, 2024
2 parents a2ee408 + c92487e commit 4ab9215
Show file tree
Hide file tree
Showing 23 changed files with 195 additions and 140 deletions.
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/CompileTimeImportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ public void Resource_derived_typed_compile_time_imports_raise_diagnostic_when_im

result.Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, """Resource type "Microsoft.Foo/bars@2022-09-01" does not have types available."""),
("BCP081", DiagnosticLevel.Warning, """Resource type "Microsoft.Foo/bars@2022-09-01" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."""),
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/ExamplesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static bool IsPermittedMissingTypeDiagnostic(IDiagnostic diagnostic)
var permittedMissingTypeDiagnostics = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
// To exclude a particular type for BCP081 (if there are missing types), add an entry of format:
// "Resource type \"<type>\" does not have types available.",
// "Resource type \"<type>\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed.",
};

return permittedMissingTypeDiagnostics.Contains(diagnostic.Message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ private static ServiceBuilder GetServiceBuilder(IFileSystem fileSystem, string r
.WithContainerRegistryClientFactory(clientFactory);
}

[TestMethod]
public async Task Radius_identifier_passing_works_as_defined()
private static async Task<ServiceBuilder> GetServicesWithPrepublishedTypes()
{
// repro for https://github.com/Azure/bicep/issues/13465
var registry = "example.azurecr.io";
var repository = $"test/radius";

Expand All @@ -35,6 +33,15 @@ public async Task Radius_identifier_passing_works_as_defined()
var tgzData = ThirdPartyTypeHelper.GetMockRadiusTypesTgz();
await RegistryHelper.PublishProviderToRegistryAsync(services.Build(), $"br:{registry}/{repository}:1.0.0", tgzData);

return services;
}

[TestMethod]
public async Task Radius_identifier_passing_works_as_defined()
{
// repro for https://github.com/Azure/bicep/issues/13465
var services = await GetServicesWithPrepublishedTypes();

var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'br:example.azurecr.io/test/[email protected]'

Expand Down Expand Up @@ -62,6 +69,30 @@ public async Task Radius_identifier_passing_works_as_defined()
}
}
}
""");

result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
}

[TestMethod]
public async Task Radius_use_of_existing_works()
{
// repro for https://github.com/Azure/bicep/issues/13423#issuecomment-2030512429
var services = await GetServicesWithPrepublishedTypes();

var result = await CompilationHelper.RestoreAndCompile(services, """
provider 'br:example.azurecr.io/test/[email protected]'

param bucketName string

resource bucket 'AWS.S3/Bucket@default' existing = {
alias: bucketName
properties: {
BucketName: bucketName
}
}

output var string = bucket.properties.BucketName
""");

result.ExcludingLinterDiagnostics().Should().NotHaveAnyDiagnostics();
Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.Core.IntegrationTests/ExtensibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void Kubernetes_CustomResourceType_EmitWarning()

result.Should().GenerateATemplate();
result.Should().HaveDiagnostics(new[] {
("BCP081", DiagnosticLevel.Warning, @"Resource type ""custom/Foo@v1"" does not have types available."),
("BCP081", DiagnosticLevel.Warning, @"Resource type ""custom/Foo@v1"" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
}

Expand Down Expand Up @@ -397,8 +397,8 @@ public void Kubernetes_AmbiguousFallbackType_MustFullyQualify()
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."),
("BCP081", DiagnosticLevel.Warning, @"Resource type ""Microsoft.Foo/bar@2023-01-01"" does not have types available."),
("BCP081", DiagnosticLevel.Warning, @"Resource type ""Microsoft.Compute/availabilitySets@2023-01-01"" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, @"Resource type ""Microsoft.Foo/bar@2023-01-01"" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
}

Expand Down Expand Up @@ -466,7 +466,7 @@ public void Child_resource_with_parent_namespace_mismatch_returns_error()
");

result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[] {
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts@2020-01-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts@2020-01-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP210", DiagnosticLevel.Error, "Resource type belonging to namespace \"stg\" cannot have a parent resource type belonging to different namespace \"az\"."),
});
}
Expand Down
10 changes: 5 additions & 5 deletions src/Bicep.Core.IntegrationTests/ModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,14 +657,14 @@ public void Module_with_unknown_resourcetype_as_parameter_and_output_has_diagnos
{
diagnosticsMap[InMemoryFileResolver.GetFileUri("/path/to/module.bicep")].Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Another.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Another.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Another.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Another.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
diagnosticsMap[InMemoryFileResolver.GetFileUri("/path/to/main.bicep")].Should().HaveDiagnostics(new[]
{
("BCP230", DiagnosticLevel.Warning, "The referenced module uses resource type \"Some.Fake/Type@2019-06-01\" which does not have types available."),
("BCP230", DiagnosticLevel.Warning, "The referenced module uses resource type \"Another.Fake/Type@2019-06-01\" which does not have types available."),
("BCP230", DiagnosticLevel.Warning, "The referenced module uses resource type \"Some.Fake/Type@2019-06-01\" which does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP230", DiagnosticLevel.Warning, "The referenced module uses resource type \"Another.Fake/Type@2019-06-01\" which does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP036", DiagnosticLevel.Error, "The property \"p\" expected a value of type \"Some.Fake/Type\" but the provided value is of type \"'something'\"."),
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/OutputsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ public void Output_can_have_warnings_for_missing_type()
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
// There are two warnings because there are two places in code to correct the missing type.
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
}

Expand All @@ -226,7 +226,7 @@ public void Output_can_have_warnings_for_missing_type_but_we_dont_duplicate_them

result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
}

Expand Down
6 changes: 3 additions & 3 deletions src/Bicep.Core.IntegrationTests/ParametersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void Parameter_can_have_warnings_for_missing_type()
");
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Some.Fake/Type@2019-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public void Parameter_with_resource_type_cannot_be_used_as_extension_scope()

result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResource@2020-01-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResource@2020-01-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP229", DiagnosticLevel.Error, "The parameter \"p\" cannot be used as a resource scope or parent. Resources passed as parameters cannot be used as a scope or parent of a resource."),
});
}
Expand All @@ -227,7 +227,7 @@ public void Parameter_with_resource_type_cannot_be_used_as_parent()

result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts/tableServices@2020-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts/tableServices@2020-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP229", DiagnosticLevel.Error, "The parameter \"p\" cannot be used as a resource scope or parent. Resources passed as parameters cannot be used as a scope or parent of a resource."),
("BCP169", DiagnosticLevel.Error, "Expected resource name to contain 1 \"/\" character(s). The number of name segments must match the number of segments in the resource type."),
});
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.IntegrationTests/RegistryProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public async Task Warning_generated_and_fallback_type_type_accepted()
result.Template.Should().HaveValueAtPath("$.resources['dadJoke']['properties']['bodyProp']", "fallback body");

result.Should().HaveDiagnostics(new[]{
("BCP081", DiagnosticLevel.Warning, "Resource type \"test@v1\" does not have types available.")
("BCP081", DiagnosticLevel.Warning, "Resource type \"test@v1\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed.")
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1060,9 +1060,9 @@ public void Test_Issue1941()
result.Template.Should().NotBeNull();
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/providers@2020-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/providers/a/b@2020-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/a/b/providers@2020-06-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/providers@2020-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/providers/a/b@2020-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Rp.A/a/b/providers@2020-06-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
});

result = CompilationHelper.Compile(@"
Expand Down Expand Up @@ -3305,7 +3305,7 @@ public void Test_Issue_3356_Warn_On_Bad_Type_Definitions()
");
result.ExcludingLinterDiagnostics().Should().HaveDiagnostics(new[]
{
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts@2021-09-00\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"Microsoft.Storage/storageAccounts@2021-09-00\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP036", DiagnosticLevel.Warning, "The property \"name\" expected a value of type \"string\" but the provided value is of type \"123\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
("BCP036", DiagnosticLevel.Warning, "The property \"capacity\" expected a value of type \"int\" but the provided value is of type \"'1'\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
("BCP036", DiagnosticLevel.Warning, "The property \"type\" expected a value of type \"string\" but the provided value is of type \"1\". If this is an inaccuracy in the documentation, please report it to the Bicep Team."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,8 @@ public void ObjectVariablesWithUnknownTypeResourceReference_ShouldBeInlined()
"));

result.ExcludingLinterDiagnostics().Should().GenerateATemplate().And.HaveDiagnostics(new[] {
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResourceType@2020-01-01\" does not have types available."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResourceType@2020-01-01\" does not have types available.")
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResourceType@2020-01-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed."),
("BCP081", DiagnosticLevel.Warning, "Resource type \"My.Rp/myResourceType@2020-01-01\" does not have types available. Bicep is unable to validate resource properties prior to deployment, but this will not block the resource from being deployed.")
});
using (new AssertionScope())
{
Expand Down
Loading

0 comments on commit 4ab9215

Please sign in to comment.