ConfigureShowCommand.cs (10076B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ConfigureShowCommand.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace AppInstallerCLIE2ETests 8 { 9 using System.IO; 10 using AppInstallerCLIE2ETests.Helpers; 11 using Microsoft.Win32; 12 using NUnit.Framework; 13 14 /// <summary> 15 /// `Configure show` command tests. 16 /// </summary> 17 public class ConfigureShowCommand 18 { 19 /// <summary> 20 /// Setup done once before all the tests here. 21 /// </summary> 22 [OneTimeSetUp] 23 public void OneTimeSetup() 24 { 25 this.DeleteResourceArtifacts(); 26 ConfigureCommand.EnsureTestResourcePresence(); 27 } 28 29 /// <summary> 30 /// One time teardown. 31 /// </summary> 32 [OneTimeTearDown] 33 public void OneTimeTearDown() 34 { 35 this.DeleteResourceArtifacts(); 36 } 37 38 /// <summary> 39 /// Simple test to confirm that a resource without a module specified can be discovered in the PSGallery. 40 /// </summary> 41 [Test] 42 [Ignore("PS Gallery tests are unreliable.")] 43 public void ShowDetailsFromGallery() 44 { 45 TestCommon.EnsureModuleState(Constants.GalleryTestModuleName, present: false); 46 47 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\PSGallery_NoModule_NoSettings.yml")} --verbose", timeOut: 120000); 48 Assert.AreEqual(0, result.ExitCode); 49 Assert.True(result.StdOut.Contains(Constants.PSGalleryName)); 50 } 51 52 /// <summary> 53 /// Simple test to confirm that a resource with a module specified can be discovered in a local repository that doesn't support resource discovery. 54 /// </summary> 55 [Test] 56 public void ShowDetailsFromTestRepo() 57 { 58 TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: false); 59 60 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\ShowDetails_TestRepo.yml")} --verbose"); 61 Assert.AreEqual(0, result.ExitCode); 62 Assert.True(result.StdOut.Contains(Constants.TestRepoName)); 63 } 64 65 /// <summary> 66 /// Simple test to confirm that a resource that is already locally available shows that way. 67 /// </summary> 68 /// <param name="location">The location the module should be before running.</param> 69 [TestCase(TestCommon.TestModuleLocation.CurrentUser)] 70 [TestCase(TestCommon.TestModuleLocation.AllUsers)] 71 [TestCase(TestCommon.TestModuleLocation.WinGetModulePath)] 72 [TestCase(TestCommon.TestModuleLocation.Custom)] 73 public void ShowDetailsFromLocal(TestCommon.TestModuleLocation location) 74 { 75 TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: true, repository: Constants.TestRepoName, location: location); 76 77 string args = $"{TestCommon.GetTestDataFile("Configuration\\ShowDetails_TestRepo.yml")} --verbose"; 78 if (location == TestCommon.TestModuleLocation.Custom) 79 { 80 args += " --module-path " + TestCommon.GetExpectedModulePath(location); 81 } 82 83 var result = TestCommon.RunAICLICommand("configure show", args); 84 Assert.AreEqual(0, result.ExitCode); 85 Assert.True(result.StdOut.Contains(Constants.LocalModuleDescriptor)); 86 } 87 88 /// <summary> 89 /// A schema 0.3 config file is allowed with the experimental feature. 90 /// </summary> 91 [Test] 92 public void ShowDetails_Schema0_3_Succeeds() 93 { 94 TestCommon.EnsureModuleState(Constants.SimpleTestModuleName, present: false); 95 96 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\ShowDetails_TestRepo_0_3.yml")} --verbose"); 97 Assert.AreEqual(0, result.ExitCode); 98 Assert.True(result.StdOut.Contains(Constants.TestRepoName)); 99 } 100 101 /// <summary> 102 /// A schema 0.3 config file with parameters is blocked. 103 /// </summary> 104 [Test] 105 public void ShowDetails_Schema0_3_Parameters() 106 { 107 var result = TestCommon.RunAICLICommand("configure show", TestCommon.GetTestDataFile("Configuration\\WithParameters_0_3.yml")); 108 Assert.AreEqual(0, result.ExitCode); 109 Assert.True(result.StdOut.Contains("Failed to get detailed information about the configuration.")); 110 } 111 112 /// <summary> 113 /// Simple test to show details from a https configuration file. 114 /// </summary> 115 [Test] 116 public void ShowDetailsFromHttpsConfigurationFile() 117 { 118 var result = TestCommon.RunAICLICommand("configure show", $"{Constants.TestSourceUrl}/TestData/Configuration/ShowDetails_TestRepo.yml --verbose"); 119 Assert.AreEqual(0, result.ExitCode); 120 Assert.True(result.StdOut.Contains(Constants.TestRepoName)); 121 } 122 123 /// <summary> 124 /// This test ensures that there is not significant overflow from large strings in the configuration file. 125 /// </summary> 126 [Test] 127 public void ShowTruncatedDetailsAndFileContent() 128 { 129 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\LargeContentStrings.yml")} --verbose"); 130 Assert.AreEqual(0, result.ExitCode); 131 Assert.True(result.StdOut.Contains("<this value has been truncated; inspect the file contents for the complete text>")); 132 Assert.True(result.StdOut.Contains("Some of the data present in the configuration file was truncated for this output; inspect the file contents for the complete content.")); 133 Assert.False(result.StdOut.Contains("Line5")); 134 } 135 136 /// <summary> 137 /// Runs a configuration, then shows it from history. 138 /// </summary> 139 [Test] 140 public void ShowFromHistory() 141 { 142 var result = TestCommon.RunAICLICommand("configure --accept-configuration-agreements --verbose", TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml")); 143 Assert.AreEqual(0, result.ExitCode); 144 145 string guid = TestCommon.GetConfigurationInstanceIdentifierFor("Configure_TestRepo.yml"); 146 result = TestCommon.RunAICLICommand("configure show", $"-h {guid}"); 147 Assert.AreEqual(0, result.ExitCode); 148 } 149 150 /// <summary> 151 /// Runs a configuration, then shows it from history. 152 /// </summary> 153 [Test] 154 public void ShowWithBadProcessorIdentifier() 155 { 156 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\Unknown_Processor.yml")} --verbose"); 157 Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_FIELD_VALUE, result.ExitCode); 158 } 159 160 /// <summary> 161 /// Simple test to confirm that a resource is discoverable with DSC v3. 162 /// </summary> 163 [Test] 164 public void ShowDetails_DSCv3() 165 { 166 var result = TestCommon.RunAICLICommand("configure show", $"{TestCommon.GetTestDataFile("Configuration\\ShowDetails_DSCv3.yml")} --verbose"); 167 Assert.AreEqual(0, result.ExitCode); 168 169 var outputLines = result.StdOut.Split('\n'); 170 int startLine = -1; 171 for (int i = 0; i < outputLines.Length; ++i) 172 { 173 if (outputLines[i].Trim() == "Microsoft.WinGet.Dev/TestFile [Test File]") 174 { 175 startLine = i; 176 } 177 } 178 179 Assert.AreNotEqual(-1, startLine); 180 Assert.LessOrEqual(3, outputLines.Length - startLine); 181 182 // outputLines[1] should contain the discovered resource string if working properly. 183 Assert.AreEqual("Description 1.", outputLines[startLine + 2].Trim()); 184 } 185 186 /// <summary> 187 /// Runs a DSCv3 configuration, then shows it from history. 188 /// </summary> 189 [Test] 190 public void ShowFromHistory_DSCv3() 191 { 192 var result = TestCommon.RunAICLICommand("configure --accept-configuration-agreements --verbose", TestCommon.GetTestDataFile("Configuration\\ShowDetails_DSCv3.yml")); 193 Assert.AreEqual(0, result.ExitCode); 194 195 string guid = TestCommon.GetConfigurationInstanceIdentifierFor("ShowDetails_DSCv3.yml"); 196 result = TestCommon.RunAICLICommand("configure show", $"-h {guid} --"); 197 Assert.AreEqual(0, result.ExitCode); 198 199 var outputLines = result.StdOut.Split('\n'); 200 int startLine = -1; 201 for (int i = 0; i < outputLines.Length; ++i) 202 { 203 if (outputLines[i].Trim() == "Microsoft.WinGet.Dev/TestFile [Test File]") 204 { 205 startLine = i; 206 } 207 } 208 209 Assert.AreNotEqual(-1, startLine); 210 Assert.LessOrEqual(3, outputLines.Length - startLine); 211 212 // outputLines[1] should contain the discovered resource string if working properly. 213 Assert.AreEqual("Description 1.", outputLines[startLine + 2].Trim()); 214 } 215 216 private void DeleteResourceArtifacts() 217 { 218 // Delete all .txt files in the test directory; they are placed there by the tests 219 foreach (string file in Directory.GetFiles(TestCommon.GetTestDataFile("Configuration"), "*.txt")) 220 { 221 File.Delete(file); 222 } 223 } 224 } 225 }