Skip to content

Commit

Permalink
Repro for radius issue (Azure#13773)
Browse files Browse the repository at this point in the history
I couldn't repro the problem reported under
Azure#13423 (comment), but
figured I'd check in the work anyway, to give more coverage of Radius
scenarios.
  • Loading branch information
anthony-c-martin committed Apr 1, 2024
1 parent dba7d80 commit a11a611
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 11 deletions.
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 @@ param basename string
}
}
}
""");

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
40 changes: 32 additions & 8 deletions src/Bicep.Core.UnitTests/Utils/ThirdPartyTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static BinaryData GetTestTypesTgz()
[fooType.Name] = new CrossFileTypeReference("types.json", factory.GetIndex(fooType)),
}, new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<CrossFileTypeReference>>>(),
settings,
null!);
null);

return GetTypesTgzBytesFromFiles(
("index.json", StreamHelper.GetString(stream => TypeSerializer.SerializeIndex(stream, index))),
Expand Down Expand Up @@ -140,6 +140,26 @@ public static BinaryData GetMockRadiusTypesTgz()

var stringType = factory.Create(() => new StringType());

var awsBucketPropertiesType = factory.Create(() => new ObjectType("properties", new Dictionary<string, ObjectTypeProperty>
{
["BucketName"] = new(factory.GetReference(stringType), ObjectTypePropertyFlags.Identifier, null),
}, null));

var awsBucketsBodyType = factory.Create(() => new ObjectType("body", new Dictionary<string, ObjectTypeProperty>
{
["name"] = new(factory.GetReference(stringType), ObjectTypePropertyFlags.None, "the resource name"),
["alias"] = new(factory.GetReference(stringType), ObjectTypePropertyFlags.Required | ObjectTypePropertyFlags.Identifier, "the resource alias"),
["properties"] = new(factory.GetReference(awsBucketPropertiesType), ObjectTypePropertyFlags.Identifier, "Bucket properties"),
}, null));

var awsBucketsType = factory.Create(() => new ResourceType(
"AWS.S3/Bucket@default",
ScopeType.Unknown,
null,
factory.GetReference(awsBucketsBodyType),
ResourceFlags.None,
null));

var environmentsBodyType = factory.Create(() => new ObjectType("body", new Dictionary<string, ObjectTypeProperty>
{
["name"] = new(factory.GetReference(stringType), ObjectTypePropertyFlags.Required | ObjectTypePropertyFlags.Identifier, "The resource name"),
Expand Down Expand Up @@ -196,14 +216,18 @@ public static BinaryData GetMockRadiusTypesTgz()

var settings = new TypeSettings(name: "Radius", version: "1.0.0", isSingleton: false, configurationType: null!);

var index = new TypeIndex(new Dictionary<string, CrossFileTypeReference>
{
[environmentsType.Name] = new CrossFileTypeReference("types.json", factory.GetIndex(environmentsType)),
[applicationsType.Name] = new CrossFileTypeReference("types.json", factory.GetIndex(applicationsType)),
[extendersType.Name] = new CrossFileTypeReference("types.json", factory.GetIndex(extendersType)),
}, new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<CrossFileTypeReference>>>(),
var resourceTypes = new[] {
environmentsType,
applicationsType,
extendersType,
awsBucketsType,
};

var index = new TypeIndex(
resourceTypes.ToDictionary(x => x.Name, x => new CrossFileTypeReference("types.json", factory.GetIndex(x))),
new Dictionary<string, IReadOnlyDictionary<string, IReadOnlyList<CrossFileTypeReference>>>(),
settings,
null!);
null);

return GetTypesTgzBytesFromFiles(
("index.json", StreamHelper.GetString(stream => TypeSerializer.SerializeIndex(stream, index))),
Expand Down

0 comments on commit a11a611

Please sign in to comment.