public async Task CheckBaselineIntegrityOnly() { const int AllowedVariance = 5; ImageSizeData[] imageSizes = new[] { new ImageSizeData(RuntimeDepsRepo, RuntimeDeps1RelativeDir, RuntimeDeps1Tag, 100, 99), new ImageSizeData(RuntimeDepsRepo, RuntimeDeps2RelativeDir, RuntimeDeps2Tag, 2, actualSize: null), new ImageSizeData(RuntimeRepo, RuntimeRelativeDir, RuntimeTag, 3, 3), new ImageSizeData(AspnetRepo, AspnetRelativeDir, AspnetTag, 100, 200), new ImageSizeData(SdkRepo, SdkRelativeDir, SdkTag, baselineSize: null, 5) }; // This will configure the test so that an exception will be thrown should the logic ever attempt to // retrieve an image size. Image sizes should not be retrieved when we're only validating baseline integrity. bool localImagesExist = false; TestContext testContext = new TestContext(imageSizes, AllowedVariance, checkBaselineIntegrityOnly: true, localImagesExist: localImagesExist); ValidateImageSizeCommand command = await testContext.RunTestAsync(); testContext.Verify(isValidationErrorExpected: true); ImageSizeValidationResults results = command.ValidationResults; Assert.Empty(results.ImagesWithNoSizeChange); Assert.Empty(results.ImagesWithAllowedSizeChange); Assert.Empty(results.ImagesWithDisallowedSizeChange); Assert.Single(results.ImagesWithMissingBaseline); Assert.Equal(SdkRelativeDir, results.ImagesWithMissingBaseline.First().Id); Assert.Single(results.ImagesWithExtraneousBaseline); Assert.Equal(RuntimeDeps2RelativeDir, results.ImagesWithExtraneousBaseline.First().Id); }
public async Task ExtraneousBaseline() { // Specifying null for the actual size prevents the image from being defined in the manifest. But since // a baseline size is defined, it'll end up in the baseline file. This is the scenario that we want to // identify because there will be extraneous data in the baseline file for which no image exists. ImageSizeData[] imageSizes = new[] { new ImageSizeData(RuntimeDepsRepo, RuntimeDeps1RelativeDir, RuntimeDeps1Tag, 1, actualSize: null), new ImageSizeData(RuntimeDepsRepo, RuntimeDeps2RelativeDir, RuntimeDeps2Tag, 2, 2), new ImageSizeData(RuntimeRepo, RuntimeRelativeDir, RuntimeTag, 3, 3), new ImageSizeData(AspnetRepo, AspnetRelativeDir, AspnetTag, 4, actualSize: null), new ImageSizeData(SdkRepo, SdkRelativeDir, SdkTag, 5, 5) }; TestContext testContext = new TestContext(imageSizes); ValidateImageSizeCommand command = await testContext.RunTestAsync(); testContext.Verify(isValidationErrorExpected: true); ImageSizeValidationResults results = command.ValidationResults; Assert.Equal(3, results.ImagesWithNoSizeChange.Count()); Assert.Equal(RuntimeDeps2RelativeDir, results.ImagesWithNoSizeChange.ElementAt(0).Id); Assert.Equal(RuntimeRelativeDir, results.ImagesWithNoSizeChange.ElementAt(1).Id); Assert.Equal(SdkRelativeDir, results.ImagesWithNoSizeChange.ElementAt(2).Id); Assert.Empty(results.ImagesWithAllowedSizeChange); Assert.Empty(results.ImagesWithDisallowedSizeChange); Assert.Empty(results.ImagesWithMissingBaseline); Assert.Equal(2, results.ImagesWithExtraneousBaseline.Count()); Assert.Equal(RuntimeDeps1RelativeDir, results.ImagesWithExtraneousBaseline.ElementAt(0).Id); Assert.Equal(AspnetRelativeDir, results.ImagesWithExtraneousBaseline.ElementAt(1).Id); }
public async Task SizeDifferences() { const int AllowedVariance = 5; // Define the test data such that some of the image sizes are within the allowed range and others are // just out of the allowed range. These numbers are all in relation to the AllowedVariance. ImageSizeData[] imageSizes = new[] { // Within range (under) new ImageSizeData(RuntimeDepsRepo, RuntimeDeps1RelativeDir, RuntimeDeps1Tag, 100, 95), // Out of range (under) new ImageSizeData(RuntimeDepsRepo, RuntimeDeps2RelativeDir, RuntimeDeps2Tag, 100, 94), // Within range (over) new ImageSizeData(RuntimeRepo, RuntimeRelativeDir, RuntimeTag, 100, 101), // Out of range (over) new ImageSizeData(AspnetRepo, AspnetRelativeDir, AspnetTag, 100, 106), // Same size new ImageSizeData(SdkRepo, SdkRelativeDir, SdkTag, 100, 100) }; TestContext testContext = new TestContext(imageSizes, AllowedVariance); ValidateImageSizeCommand command = await testContext.RunTestAsync(); testContext.Verify(isValidationErrorExpected: true); ImageSizeValidationResults results = command.ValidationResults; Assert.Single(results.ImagesWithNoSizeChange); Assert.Equal(SdkRelativeDir, results.ImagesWithNoSizeChange.First().Id); Assert.Equal(2, results.ImagesWithAllowedSizeChange.Count()); Assert.Equal(RuntimeDeps1RelativeDir, results.ImagesWithAllowedSizeChange.ElementAt(0).Id); Assert.Equal(RuntimeRelativeDir, results.ImagesWithAllowedSizeChange.ElementAt(1).Id); Assert.Equal(2, results.ImagesWithDisallowedSizeChange.Count()); Assert.Equal(RuntimeDeps2RelativeDir, results.ImagesWithDisallowedSizeChange.ElementAt(0).Id); Assert.Equal(AspnetRelativeDir, results.ImagesWithDisallowedSizeChange.ElementAt(1).Id); Assert.Empty(results.ImagesWithMissingBaseline); Assert.Empty(results.ImagesWithExtraneousBaseline); }
public async Task <ValidateImageSizeCommand> RunTestAsync() { using TempFolderContext tempFolderContext = TestHelper.UseTempFolder(); // Use the image size data defined by the test case to generate a baseline file string baselinePath = Path.Combine(tempFolderContext.Path, "baseline.json"); CreateBaselineFile(baselinePath, this.imageSizes); // Use the image size data defined by the test to provide mock values for the image sizes // from the DockerService. Mock <IDockerService> dockerServiceMock = new Mock <IDockerService>(); dockerServiceMock .Setup(o => o.LocalImageExists(It.IsAny <string>(), It.IsAny <bool>())) .Returns(this.localImagesExist); SetupDockerServiceImageSizes(dockerServiceMock, this.imageSizes); // Setup the command ValidateImageSizeCommand command = new ValidateImageSizeCommand( dockerServiceMock.Object, Mock.Of <ILoggerService>(), environmentServiceMock.Object); command.Options.Manifest = Path.Combine(tempFolderContext.Path, "manifest.json"); command.Options.BaselinePath = baselinePath; command.Options.AllowedVariance = this.allowedVariance ?? 0; command.Options.CheckBaselineIntegrityOnly = this.checkBaselineIntegrityOnly; command.Options.IsPullEnabled = false; // Use the image size data defined by the test to generate a manifest file Manifest manifest = CreateTestManifest(tempFolderContext.Path, this.imageSizes); File.WriteAllText(Path.Combine(tempFolderContext.Path, command.Options.Manifest), JsonConvert.SerializeObject(manifest)); // Execute the command command.LoadManifest(); await command.ExecuteAsync(); return(command); }
public async Task NoSizeDifferences() { ImageSizeData[] imageSizes = new [] { new ImageSizeData(RuntimeDepsRepo, RuntimeDeps1RelativeDir, RuntimeDeps1Tag, 1, 1), new ImageSizeData(RuntimeDepsRepo, RuntimeDeps2RelativeDir, RuntimeDeps2Tag, 2, 2), new ImageSizeData(RuntimeRepo, RuntimeRelativeDir, RuntimeTag, 3, 3), new ImageSizeData(AspnetRepo, AspnetRelativeDir, AspnetTag, 4, 4), new ImageSizeData(SdkRepo, SdkRelativeDir, SdkTag, 5, 5) }; TestContext testContext = new TestContext(imageSizes); ValidateImageSizeCommand command = await testContext.RunTestAsync(); testContext.Verify(isValidationErrorExpected: false); ImageSizeValidationResults results = command.ValidationResults; Assert.Equal(5, results.ImagesWithNoSizeChange.Count()); Assert.Empty(results.ImagesWithAllowedSizeChange); Assert.Empty(results.ImagesWithDisallowedSizeChange); Assert.Empty(results.ImagesWithMissingBaseline); Assert.Empty(results.ImagesWithExtraneousBaseline); }