From 9eac17a8ab63f157253a74828b0fbd593f53d71a Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 25 Apr 2021 23:35:50 -0500 Subject: Add tests for #5253 and #5586. --- src/TestData/CacheTests/BundleA/BundleA.wixproj | 19 ++++ src/TestData/CacheTests/BundleA/BundleA.wxs | 11 +++ src/TestData/CacheTests/BundleB/BundleB.wixproj | 19 ++++ src/TestData/CacheTests/BundleB/BundleB.wxs | 11 +++ src/TestData/CacheTests/PackageA/PackageA.wixproj | 9 ++ src/TestData/CacheTests/PackageB/PackageB.wixproj | 9 ++ src/WixTestTools/BundleInstaller.cs | 12 +++ src/WixToolsetTest.BurnE2E/CacheTests.cs | 106 ++++++++++++++++++++++ 8 files changed, 196 insertions(+) create mode 100644 src/TestData/CacheTests/BundleA/BundleA.wixproj create mode 100644 src/TestData/CacheTests/BundleA/BundleA.wxs create mode 100644 src/TestData/CacheTests/BundleB/BundleB.wixproj create mode 100644 src/TestData/CacheTests/BundleB/BundleB.wxs create mode 100644 src/TestData/CacheTests/PackageA/PackageA.wixproj create mode 100644 src/TestData/CacheTests/PackageB/PackageB.wixproj create mode 100644 src/WixToolsetTest.BurnE2E/CacheTests.cs (limited to 'src') diff --git a/src/TestData/CacheTests/BundleA/BundleA.wixproj b/src/TestData/CacheTests/BundleA/BundleA.wixproj new file mode 100644 index 00000000..5071c1c7 --- /dev/null +++ b/src/TestData/CacheTests/BundleA/BundleA.wixproj @@ -0,0 +1,19 @@ + + + + Bundle + {C48D0F58-0F8F-461D-A60D-D83E5F35BA8E} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/CacheTests/BundleA/BundleA.wxs b/src/TestData/CacheTests/BundleA/BundleA.wxs new file mode 100644 index 00000000..20262187 --- /dev/null +++ b/src/TestData/CacheTests/BundleA/BundleA.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/TestData/CacheTests/BundleB/BundleB.wixproj b/src/TestData/CacheTests/BundleB/BundleB.wixproj new file mode 100644 index 00000000..ffc03f79 --- /dev/null +++ b/src/TestData/CacheTests/BundleB/BundleB.wixproj @@ -0,0 +1,19 @@ + + + + Bundle + {3CC71AD2-39F3-4803-A24C-6E6A492B721C} + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/TestData/CacheTests/BundleB/BundleB.wxs b/src/TestData/CacheTests/BundleB/BundleB.wxs new file mode 100644 index 00000000..95e714ec --- /dev/null +++ b/src/TestData/CacheTests/BundleB/BundleB.wxs @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/TestData/CacheTests/PackageA/PackageA.wixproj b/src/TestData/CacheTests/PackageA/PackageA.wixproj new file mode 100644 index 00000000..dd8176ed --- /dev/null +++ b/src/TestData/CacheTests/PackageA/PackageA.wixproj @@ -0,0 +1,9 @@ + + + + {5D0BD93A-D1D8-4F59-8417-1390B18A6611} + + + + + \ No newline at end of file diff --git a/src/TestData/CacheTests/PackageB/PackageB.wixproj b/src/TestData/CacheTests/PackageB/PackageB.wixproj new file mode 100644 index 00000000..efc57bb6 --- /dev/null +++ b/src/TestData/CacheTests/PackageB/PackageB.wixproj @@ -0,0 +1,9 @@ + + + + {ADCE5902-224D-4C87-BA31-2D154B37EE22} + + + + + \ No newline at end of file diff --git a/src/WixTestTools/BundleInstaller.cs b/src/WixTestTools/BundleInstaller.cs index 34661651..a49c4024 100644 --- a/src/WixTestTools/BundleInstaller.cs +++ b/src/WixTestTools/BundleInstaller.cs @@ -84,6 +84,18 @@ namespace WixTestTools return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Modify, arguments); } + /// + /// Modify the bundle with optional arguments. + /// + /// This should be the bundle in the package cache. + /// Expected exit code, defaults to success. + /// Optional arguments to pass to the tool. + /// Path to the generated log file. + public string Modify(string bundlePath, int expectedExitCode = (int)MSIExec.MSIExecReturnCode.SUCCESS, params string[] arguments) + { + return this.RunBundleWithArguments(expectedExitCode, MSIExec.MSIExecMode.Modify, arguments, bundlePath: bundlePath); + } + /// /// Repairs the bundle with optional arguments. /// diff --git a/src/WixToolsetTest.BurnE2E/CacheTests.cs b/src/WixToolsetTest.BurnE2E/CacheTests.cs new file mode 100644 index 00000000..f62b0874 --- /dev/null +++ b/src/WixToolsetTest.BurnE2E/CacheTests.cs @@ -0,0 +1,106 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolsetTest.BurnE2E +{ + using System.Collections.Generic; + using System.IO; + using WixBuildTools.TestSupport; + using WixToolset.Mba.Core; + using Xunit; + using Xunit.Abstractions; + + public class CacheTests : BurnE2ETests + { + public CacheTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { } + + [Fact] + public void CanDownloadPayloadsFromMissingAttachedContainer() + { + var packageA = this.CreatePackageInstaller("PackageA"); + var packageB = this.CreatePackageInstaller("PackageB"); + var bundleA = this.CreateBundleInstaller("BundleA"); + var testBAController = this.CreateTestBAController(); + var webServer = this.CreateWebServer(); + + webServer.AddFiles(new Dictionary + { + { "/BundleA/PackageA.msi", Path.Combine(this.TestContext.TestDataFolder, "PackageA.msi") }, + { "/BundleA/PackageB.msi", Path.Combine(this.TestContext.TestDataFolder, "PackageB.msi") }, + }); + webServer.Start(); + + // Don't install PackageB initially so it will be installed when run from the package cache. + testBAController.SetPackageRequestedState("PackageB", RequestState.Absent); + + packageA.VerifyInstalled(false); + packageB.VerifyInstalled(false); + + // Manually copy bundle to separate directory, install from there, and then delete it + // so that when run from the package cache, it can't find the attached container. + using (var dfs = new DisposableFileSystem()) + { + var tempDirectory = dfs.GetFolder(true); + + var bundleAFileInfo = new FileInfo(bundleA.Bundle); + var bundleACopiedPath = Path.Combine(tempDirectory, bundleAFileInfo.Name); + bundleAFileInfo.CopyTo(bundleACopiedPath); + + bundleA.Install(bundleACopiedPath); + } + + var bundlePackageCachePath = bundleA.VerifyRegisteredAndInPackageCache(); + + packageA.VerifyInstalled(true); + packageB.VerifyInstalled(false); + + testBAController.SetPackageRequestedState("PackageB", RequestState.Present); + + bundleA.Modify(bundlePackageCachePath); + bundleA.VerifyRegisteredAndInPackageCache(); + + packageA.VerifyInstalled(true); + packageB.VerifyInstalled(true); + } + + [Fact] + public void CanFindAttachedContainerFromRenamedBundle() + { + var packageA = this.CreatePackageInstaller("PackageA"); + var packageB = this.CreatePackageInstaller("PackageB"); + var bundleB = this.CreateBundleInstaller("BundleB"); + var testBAController = this.CreateTestBAController(); + + // Don't install PackageB initially so it will be installed when run from the package cache. + testBAController.SetPackageRequestedState("PackageB", RequestState.Absent); + + packageA.VerifyInstalled(false); + packageB.VerifyInstalled(false); + + // Manually copy bundle to separate directory with new name and install from there + // so that when run from the package cache, it has to get the attached container from the renamed bundle. + using (var dfs = new DisposableFileSystem()) + { + var tempDirectory = dfs.GetFolder(true); + + var bundleBFileInfo = new FileInfo(bundleB.Bundle); + var bundleBCopiedPath = Path.Combine(tempDirectory, "RenamedBundle.exe"); + bundleBFileInfo.CopyTo(bundleBCopiedPath); + + bundleB.Install(bundleBCopiedPath); + + var bundlePackageCachePath = bundleB.VerifyRegisteredAndInPackageCache(); + + packageA.VerifyInstalled(true); + packageB.VerifyInstalled(false); + + testBAController.SetPackageRequestedState("PackageB", RequestState.Present); + + bundleB.Modify(bundlePackageCachePath); + bundleB.VerifyRegisteredAndInPackageCache(); + + packageA.VerifyInstalled(true); + packageB.VerifyInstalled(true); + } + } + } +} -- cgit v1.2.3-55-g6feb