Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Jun 6, 2024
1 parent cc84fad commit 8f7ca14
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ public async Task Build_Valid_SingleFile_WithProviderDeclarationStatement(
foreach (var ((uri, _), client) in blobClients)
{
if (uri.Host.Contains("invalid")) { continue; }
await client.SetManifestAsync(BicepTestConstants.BicepProviderManifestWithEmptyTypesLayer, "2.0.0");
await client.UploadBlobAsync(new MemoryStream());
var layer = await client.UploadBlobAsync(BinaryData.FromString(""));
var config = await client.UploadBlobAsync(BinaryData.FromString("{}"));
await client.SetManifestAsync(BicepTestConstants.GetBicepProviderManifest(layer, config), "2.0.0");
}

// 3. create a main.bicep and save it to a output directory
Expand Down
5 changes: 2 additions & 3 deletions src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ private async Task<ServiceBuilder> ServicesWithTestProviderArtifact(ArtifactRegi
(var clientFactory, var blobClients) = RegistryUtils.CreateMockRegistryClients(artifactRegistryAddress.ClientDescriptor());

(_, var client) = blobClients.First();
var configResult = await client.UploadBlobAsync(BinaryData.FromString("{}"));
var blobResult = await client.UploadBlobAsync(artifactPayload);
var manifest = BicepTestConstants.GetBicepProviderManifest(
blobResult.Value.Digest,
blobResult.Value.SizeInBytes);
var manifest = BicepTestConstants.GetBicepProviderManifest(blobResult.Value, configResult.Value);
await client.SetManifestAsync(manifest, artifactRegistryAddress.ProviderVersion);

var cacheRoot = FileHelper.GetUniqueTestOutputPath(TestContext);
Expand Down
14 changes: 6 additions & 8 deletions src/Bicep.Core.UnitTests/BicepTestConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Immutable;
using System.IO.Abstractions;
using Azure.Containers.ContainerRegistry;
using Bicep.Core.Analyzers.Linter;
using Bicep.Core.Analyzers.Linter.Rules;
using Bicep.Core.Configuration;
Expand Down Expand Up @@ -136,25 +137,22 @@ public static Mock<ITelemetryProvider> CreateMockTelemetryProvider()
return telemetryProvider;
}

public static BinaryData BicepProviderManifestWithEmptyTypesLayer
=> GetBicepProviderManifest("sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 0);

public static BinaryData GetBicepProviderManifest(string digest, long size) =>
public static BinaryData GetBicepProviderManifest(UploadRegistryBlobResult layer, UploadRegistryBlobResult config) =>
BinaryData.FromString($$"""
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"artifactType": "{{BicepMediaTypes.BicepProviderArtifactType}}",
"config": {
"mediaType": "{{BicepMediaTypes.BicepProviderConfigV1}}",
"digest": "sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a",
"size": 2
"digest": "{{config.Digest}}",
"size": {{config.SizeInBytes}}
},
"layers": [
{
"mediaType": "{{BicepMediaTypes.BicepProviderArtifactLayerV1TarGzip}}",
"digest": "{{digest}}",
"size": {{size}}
"digest": "{{layer.Digest}}",
"size": {{layer.SizeInBytes}}
}
],
"annotations": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<PackageReference Include="MSTest.TestAdapter" Version="3.2.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.3.1" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.63.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Bicep.Local.Extension;
using Bicep.Local.Extension.Rpc;
using Bicep.Local.Extension.Protocol;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.DependencyInjection;

namespace Bicep.Local.Deploy.IntegrationTests;

[TestClass]
public class KestrelProviderExtension : ProviderExtension
{
protected override async Task RunServer(string socketPath, ResourceDispatcher dispatcher, CancellationToken cancellationToken)
{
var builder = WebApplication.CreateBuilder();
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenUnixSocket(socketPath, listenOptions =>
{
listenOptions.Protocols = HttpProtocols.Http2;
});
});

builder.Services.AddGrpc();
builder.Services.AddSingleton(dispatcher);
var app = builder.Build();
app.MapGrpcService<BicepExtensionImpl>();

await app.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private async Task RunExtensionTest(Action<ResourceDispatcherBuilder> registerHa
await Task.WhenAll(
Task.Run(async () =>
{
var extension = new ProviderExtension();
var extension = new KestrelProviderExtension();

await extension.RunAsync(["--socket", socketPath], registerHandlers, cts.Token);
}),
Expand Down
9 changes: 9 additions & 0 deletions src/Bicep.Local.Deploy.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
"System.Configuration.ConfigurationManager": "4.4.0"
}
},
"Grpc.AspNetCore.Server": {
"type": "Direct",
"requested": "[2.63.0, )",
"resolved": "2.63.0",
"contentHash": "KoOz6f23k9p9+NnQw78MiMAUYNOZ8HqATcdS2Q6f9K+F8EMJbj2+Vcie88z1OpLc+7iObr4PbK3Xmf4Nm5XbGw==",
"dependencies": {
"Grpc.Net.Common": "2.63.0"
}
},
"Microsoft.CodeAnalysis.BannedApiAnalyzers": {
"type": "Direct",
"requested": "[3.3.4, )",
Expand Down

0 comments on commit 8f7ca14

Please sign in to comment.