From 8f7ca141ff45df6e531588800d02ced4adc33da5 Mon Sep 17 00:00:00 2001 From: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:38:50 -0400 Subject: [PATCH] Fix tests --- .../BuildCommandTests.cs | 5 +-- .../DynamicAzTypesTests.cs | 5 ++- .../BicepTestConstants.cs | 14 ++++---- ...Bicep.Local.Deploy.IntegrationTests.csproj | 1 + .../KestrelProviderExtension.cs | 36 +++++++++++++++++++ .../ProviderExtensionTests.cs | 2 +- .../packages.lock.json | 9 +++++ 7 files changed, 58 insertions(+), 14 deletions(-) create mode 100644 src/Bicep.Local.Deploy.IntegrationTests/KestrelProviderExtension.cs diff --git a/src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs b/src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs index ed4af31f70c..da656bc7173 100644 --- a/src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs +++ b/src/Bicep.Cli.IntegrationTests/BuildCommandTests.cs @@ -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 diff --git a/src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs b/src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs index 92526a7f713..e4fcb919a46 100644 --- a/src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs +++ b/src/Bicep.Core.IntegrationTests/DynamicAzTypesTests.cs @@ -43,10 +43,9 @@ private async Task 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); diff --git a/src/Bicep.Core.UnitTests/BicepTestConstants.cs b/src/Bicep.Core.UnitTests/BicepTestConstants.cs index 92ccbe074da..e8aefa939e1 100644 --- a/src/Bicep.Core.UnitTests/BicepTestConstants.cs +++ b/src/Bicep.Core.UnitTests/BicepTestConstants.cs @@ -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; @@ -136,10 +137,7 @@ public static Mock 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, @@ -147,14 +145,14 @@ public static BinaryData GetBicepProviderManifest(string digest, long size) => "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": { diff --git a/src/Bicep.Local.Deploy.IntegrationTests/Bicep.Local.Deploy.IntegrationTests.csproj b/src/Bicep.Local.Deploy.IntegrationTests/Bicep.Local.Deploy.IntegrationTests.csproj index a3f245b2987..bf91835908c 100644 --- a/src/Bicep.Local.Deploy.IntegrationTests/Bicep.Local.Deploy.IntegrationTests.csproj +++ b/src/Bicep.Local.Deploy.IntegrationTests/Bicep.Local.Deploy.IntegrationTests.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Bicep.Local.Deploy.IntegrationTests/KestrelProviderExtension.cs b/src/Bicep.Local.Deploy.IntegrationTests/KestrelProviderExtension.cs new file mode 100644 index 00000000000..265652c3fb2 --- /dev/null +++ b/src/Bicep.Local.Deploy.IntegrationTests/KestrelProviderExtension.cs @@ -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(); + + await app.RunAsync(); + } +} \ No newline at end of file diff --git a/src/Bicep.Local.Deploy.IntegrationTests/ProviderExtensionTests.cs b/src/Bicep.Local.Deploy.IntegrationTests/ProviderExtensionTests.cs index b5d38ffe236..0cbb2fd3350 100644 --- a/src/Bicep.Local.Deploy.IntegrationTests/ProviderExtensionTests.cs +++ b/src/Bicep.Local.Deploy.IntegrationTests/ProviderExtensionTests.cs @@ -35,7 +35,7 @@ private async Task RunExtensionTest(Action registerHa await Task.WhenAll( Task.Run(async () => { - var extension = new ProviderExtension(); + var extension = new KestrelProviderExtension(); await extension.RunAsync(["--socket", socketPath], registerHandlers, cts.Token); }), diff --git a/src/Bicep.Local.Deploy.IntegrationTests/packages.lock.json b/src/Bicep.Local.Deploy.IntegrationTests/packages.lock.json index 7ea9acf4094..19996dec562 100644 --- a/src/Bicep.Local.Deploy.IntegrationTests/packages.lock.json +++ b/src/Bicep.Local.Deploy.IntegrationTests/packages.lock.json @@ -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, )",