/// <summary> /// Ensures that the <see cref="TestDistroName"/> does not exist from a past test run. /// </summary> public static void RemoveTestDistro() { if (Wsl2Proxy.Exists(TestDistroName)) { Wsl2Proxy.Unregister(TestDistroName); } }
public async Task ImportExport() { // Verify that we can import and export distributions. var imagePath = await TestHelper.GetTestImageAsync(); using (var tempFolder = new TempFolder()) { try { //--------------------------------------------------------- // Import the distribution and verify that we can execute a command. Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); Assert.True(Wsl2Proxy.Exists(TestHelper.TestDistroName)); var distro = new Wsl2Proxy(TestHelper.TestDistroName); Assert.Equal(TestHelper.TestDistroName, distro.Name); Assert.Contains("Hello World!", distro.Execute("echo", "Hello World!").OutputText); //--------------------------------------------------------- // Terminate the distribution and verify that we can export it. var exportPath = Path.Combine(tempFolder.Path, "export.tar"); Wsl2Proxy.Terminate(TestHelper.TestDistroName); Wsl2Proxy.Export(TestHelper.TestDistroName, exportPath); //--------------------------------------------------------- // Remove the test distribution and verify that we can regenerate // it from the image we just exported. TestHelper.RemoveTestDistro(); Wsl2Proxy.Import(TestHelper.TestDistroName, exportPath, tempFolder.Path); Assert.True(Wsl2Proxy.Exists(TestHelper.TestDistroName)); distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); Assert.Contains("Hello World!", distro.Execute("echo", "Hello World!").OutputText); } finally { TestHelper.RemoveTestDistro(); } } }
public async Task NoSudoPassword() { // Verify that the distribution doesn't prompt for a SUDO password. var imagePath = await TestHelper.GetTestImageAsync(); using (var tempFolder = new TempFolder()) { try { Wsl2Proxy.Import(TestHelper.TestDistroName, imagePath, tempFolder.Path); Assert.True(Wsl2Proxy.Exists(TestHelper.TestDistroName)); var distro = new Wsl2Proxy(TestHelper.TestDistroName, user: KubeConst.SysAdminUser); Assert.Contains("Hello World!", distro.SudoExecute("echo", "Hello World!").OutputText); } finally { TestHelper.RemoveTestDistro(); } } }