public async Task Publish_InvalidFile_ShouldFail_WithExpectedErrorMessage(DataSet dataSet) { var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext); var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain); // publish won't actually happen, so broken client factory is fine var settings = new InvocationSettings(BicepTestConstants.CreateFeaturesProvider(TestContext, registryEnabled: true), BicepTestConstants.ClientFactory, BicepTestConstants.TemplateSpecRepositoryFactory); var diagnostics = GetAllDiagnostics(bicepFilePath, settings.ClientFactory, settings.TemplateSpecRepositoryFactory); var(output, error, result) = await Bicep(settings, "publish", bicepFilePath, "--target", $"br:example.com/fail/{dataSet.Name.ToLowerInvariant()}:v1"); using (new AssertionScope()) { result.Should().Be(1); output.Should().BeEmpty(); error.Should().ContainAll(diagnostics); } }
public async Task Publish_ValidFile_ShouldSucceed(DataSet dataSet) { var outputDirectory = dataSet.SaveFilesToTestDirectory(TestContext); var registryStr = "example.com"; var registryUri = new Uri($"https://{registryStr}"); var repository = $"test/{dataSet.Name}".ToLowerInvariant(); var clientFactory = dataSet.CreateMockRegistryClients(TestContext, (registryUri, repository)); var templateSpecRepositoryFactory = dataSet.CreateMockTemplateSpecRepositoryFactory(TestContext); await dataSet.PublishModulesToRegistryAsync(clientFactory, TestContext); var bicepFilePath = Path.Combine(outputDirectory, DataSet.TestFileMain); var compiledFilePath = Path.Combine(outputDirectory, DataSet.TestFileMainCompiled); // mock client factory caches the clients var testClient = (MockRegistryBlobClient)clientFactory.CreateAuthenticatedBlobClient(BicepTestConstants.BuiltInConfiguration, registryUri, repository); var settings = new InvocationSettings(BicepTestConstants.CreateFeaturesProvider(TestContext, registryEnabled: true), clientFactory, templateSpecRepositoryFactory); var(output, error, result) = await Bicep(settings, "publish", bicepFilePath, "--target", $"br:{registryStr}/{repository}:v1"); result.Should().Be(0); output.Should().BeEmpty(); AssertNoErrors(error); using var expectedCompiledStream = new FileStream(compiledFilePath, FileMode.Open, FileAccess.Read); // verify the module was published testClient.Should().OnlyHaveModule("v1", expectedCompiledStream); // publish the same content again var(output2, error2, result2) = await Bicep(settings, "publish", bicepFilePath, "--target", $"br:{registryStr}/{repository}:v1"); result2.Should().Be(0); output2.Should().BeEmpty(); AssertNoErrors(error2); // we should still only have 1 module expectedCompiledStream.Position = 0; testClient.Should().OnlyHaveModule("v1", expectedCompiledStream); }