winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

ConfigureValidateCommand.cs (14308B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="ConfigureValidateCommand.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace AppInstallerCLIE2ETests
      8 {
      9     using AppInstallerCLIE2ETests.Helpers;
     10     using NUnit.Framework;
     11 
     12     /// <summary>
     13     /// `Configure validate` command tests.
     14     /// </summary>
     15     public class ConfigureValidateCommand
     16     {
     17         private const string Command = "configure validate";
     18 
     19         /// <summary>
     20         /// Set up.
     21         /// </summary>
     22         [OneTimeSetUp]
     23         public void BaseSetup()
     24         {
     25             TestCommon.SetupTestSource(false);
     26         }
     27 
     28         /// <summary>
     29         /// Tear down.
     30         /// </summary>
     31         [OneTimeTearDown]
     32         public void BaseTeardown()
     33         {
     34             TestCommon.TearDownTestSource();
     35         }
     36 
     37         /// <summary>
     38         /// The configuration file is empty.
     39         /// </summary>
     40         [Test]
     41         public void EmptyFile()
     42         {
     43             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\Empty.yml"));
     44             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_YAML, result.ExitCode);
     45         }
     46 
     47         /// <summary>
     48         /// The configuration file is not configuration YAML.
     49         /// </summary>
     50         [Test]
     51         public void NotConfigurationYAML()
     52         {
     53             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\NotConfig.yml"));
     54             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_MISSING_FIELD, result.ExitCode);
     55             Assert.True(result.StdOut.Contains("$schema"));
     56             Assert.True(result.StdOut.Contains("missing"));
     57         }
     58 
     59         /// <summary>
     60         /// The configuration file does not specify the schema version.
     61         /// </summary>
     62         [Test]
     63         public void NoVersion()
     64         {
     65             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\NoVersion.yml"));
     66             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_MISSING_FIELD, result.ExitCode);
     67             Assert.True(result.StdOut.Contains("configurationVersion"));
     68             Assert.True(result.StdOut.Contains("missing"));
     69         }
     70 
     71         /// <summary>
     72         /// The configuration file schema version is not known.
     73         /// </summary>
     74         [Test]
     75         public void UnknownVersion()
     76         {
     77             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\UnknownVersion.yml"));
     78             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_UNKNOWN_CONFIGURATION_FILE_VERSION, result.ExitCode);
     79             Assert.True(result.StdOut.Contains("Configuration file version"));
     80             Assert.True(result.StdOut.Contains("is not known."));
     81         }
     82 
     83         /// <summary>
     84         /// The resources node is not the correct type in YAML.
     85         /// </summary>
     86         [Test]
     87         public void ResourcesIsWrongType()
     88         {
     89             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\ResourcesNotASequence.yml"));
     90             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_FIELD_TYPE, result.ExitCode);
     91             Assert.True(result.StdOut.Contains("resources"));
     92             Assert.True(result.StdOut.Contains("wrong type"));
     93         }
     94 
     95         /// <summary>
     96         /// The unit node is not the correct type in YAML.
     97         /// </summary>
     98         [Test]
     99         public void UnitIsWrongType()
    100         {
    101             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\UnitNotAMap.yml"));
    102             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_FIELD_TYPE, result.ExitCode);
    103             Assert.True(result.StdOut.Contains("resources[0]"));
    104             Assert.True(result.StdOut.Contains("wrong type"));
    105         }
    106 
    107         /// <summary>
    108         /// The resource name is missing.
    109         /// </summary>
    110         [Test]
    111         public void NoResourceName()
    112         {
    113             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\NoResourceName.yml"));
    114             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_FIELD_VALUE, result.ExitCode);
    115             Assert.True(result.StdOut.Contains("resource"));
    116             Assert.True(result.StdOut.Contains("invalid value"));
    117             Assert.True(result.StdOut.Contains("Module/"));
    118         }
    119 
    120         /// <summary>
    121         /// The resource name module does not match the directives module.
    122         /// </summary>
    123         [Test]
    124         public void ModuleMismatch()
    125         {
    126             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\ModuleMismatch.yml"));
    127             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_INVALID_FIELD_VALUE, result.ExitCode);
    128             Assert.True(result.StdOut.Contains("module"));
    129             Assert.True(result.StdOut.Contains("invalid value"));
    130             Assert.True(result.StdOut.Contains("DifferentModule"));
    131         }
    132 
    133         /// <summary>
    134         /// The configuration contains multiple resources with the same identifier.
    135         /// </summary>
    136         [Test]
    137         public void DuplicateIdentifiers()
    138         {
    139             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\DuplicateIdentifiers.yml"));
    140             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_DUPLICATE_IDENTIFIER, result.ExitCode);
    141             Assert.True(result.StdOut.Contains("The configuration contains the identifier `same` multiple times."));
    142             Assert.False(result.StdOut.Contains("NotMentioned"));
    143         }
    144 
    145         /// <summary>
    146         /// The configuration does not contain the dependency.
    147         /// </summary>
    148         [Test]
    149         public void MissingDependency()
    150         {
    151             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\MissingDependency.yml"));
    152             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_MISSING_DEPENDENCY, result.ExitCode);
    153             Assert.True(result.StdOut.Contains("The dependency `missing` was not found within the configuration."));
    154             Assert.False(result.StdOut.Contains("xE2ETestResource"));
    155         }
    156 
    157         /// <summary>
    158         /// The configuration contains a dependency cycle.
    159         /// </summary>
    160         [Test]
    161         public void DependencyCycle()
    162         {
    163             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\DependencyCycle.yml"));
    164             Assert.AreEqual(Constants.ErrorCode.CONFIG_ERROR_SET_DEPENDENCY_CYCLE, result.ExitCode);
    165             Assert.True(result.StdOut.Contains("This configuration unit is part of a dependency cycle."));
    166             Assert.False(result.StdOut.Contains("NotMentioned"));
    167         }
    168 
    169         /// <summary>
    170         /// The configuration unit is not available in a public catalog.
    171         /// </summary>
    172         [Test]
    173         public void ResourceIsNotPublic()
    174         {
    175             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\Configure_TestRepo.yml"));
    176             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    177             Assert.True(result.StdOut.Contains("not available publicly"));
    178         }
    179 
    180         /// <summary>
    181         /// The configuration unit is not found.
    182         /// </summary>
    183         [Test]
    184         public void ResourceIsNotFound()
    185         {
    186             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\ResourceNotFound.yml"));
    187             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    188             Assert.True(result.StdOut.Contains("The configuration unit could not be found."));
    189         }
    190 
    191         /// <summary>
    192         /// The module was not provided.
    193         /// </summary>
    194         [Test]
    195         public void ModuleNotProvided()
    196         {
    197             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\PSGallery_NoModule_NoSettings.yml"), timeOut: 120000);
    198             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    199             Assert.True(result.StdOut.Contains("The module was not provided."));
    200         }
    201 
    202         /// <summary>
    203         /// No issues detected (yet).
    204         /// </summary>
    205         [Test]
    206         public void NoIssuesDetected()
    207         {
    208             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\PSGallery_NoSettings.yml"), timeOut: 120000);
    209             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    210             Assert.True(result.StdOut.Contains("Validation found no issues."));
    211         }
    212 
    213         /// <summary>
    214         /// No issues detected (yet) from https configuration file.
    215         /// </summary>
    216         [Test]
    217         public void NoIssuesDetected_HttpsConfigurationFile()
    218         {
    219             var result = TestCommon.RunAICLICommand(Command, $"{Constants.TestSourceUrl}/TestData/Configuration/PSGallery_NoSettings.yml", timeOut: 120000);
    220             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    221             Assert.True(result.StdOut.Contains("Validation found no issues."));
    222         }
    223 
    224         /// <summary>
    225         /// No issues detected from WinGet resource units.
    226         /// </summary>
    227         [Test]
    228         public void NoIssuesDetected_WinGetDscResource()
    229         {
    230             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_Good.yml"), timeOut: 120000);
    231             Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode);
    232             Assert.True(result.StdOut.Contains("Validation found no issues."));
    233         }
    234 
    235         /// <summary>
    236         /// No issues detected from WinGet resource units.
    237         /// </summary>
    238         [Test]
    239         public void ValidateWinGetDscResource_DependencySourceMissing()
    240         {
    241             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_DependencySourceMissing.yml"), timeOut: 120000);
    242             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    243             Assert.True(result.StdOut.Contains("WinGetPackage configuration unit package depends on a third-party source not previously configured. Package Id: AppInstallerTest.TestExeInstaller; Source: TestSource"));
    244         }
    245 
    246         /// <summary>
    247         /// No issues detected from WinGet resource units.
    248         /// </summary>
    249         [Test]
    250         public void ValidateWinGetDscResource_PackageNotFound()
    251         {
    252             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_PackageNotFound.yml"), timeOut: 120000);
    253             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    254             Assert.True(result.StdOut.Contains("WinGetPackage configuration unit package cannot be validated. Package not found. Package Id: AppInstallerTest.DoesNotExist"));
    255         }
    256 
    257         /// <summary>
    258         /// No issues detected from WinGet resource units.
    259         /// </summary>
    260         [Test]
    261         public void ValidateWinGetDscResource_PackageVersionNotFound()
    262         {
    263             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_PackageVersionNotFound.yml"), timeOut: 120000);
    264             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    265             Assert.True(result.StdOut.Contains("WinGetPackage configuration unit package cannot be validated. Package version not found. Package Id: AppInstallerTest.TestExeInstaller; Version 101.0.101.0"));
    266         }
    267 
    268         /// <summary>
    269         /// No issues detected from WinGet resource units.
    270         /// </summary>
    271         [Test]
    272         public void ValidateWinGetDscResource_SourceOpenFailed()
    273         {
    274             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_SourceOpenFailed.yml"), timeOut: 120000);
    275             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    276             Assert.True(result.StdOut.Contains("WinGetPackage configuration unit package cannot be validated. Source open failed. Package Id: AppInstallerTest.TestExeInstaller; Source: TestSourceV2"));
    277         }
    278 
    279         /// <summary>
    280         /// No issues detected from WinGet resource units.
    281         /// </summary>
    282         [Test]
    283         public void ValidateWinGetDscResource_VersionSpecifiedWithOnlyOneVersionAvailable()
    284         {
    285             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_VersionSpecifiedWithOnlyOneVersionAvailable.yml"), timeOut: 120000);
    286             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    287             Assert.True(result.StdOut.Contains("WinGetPackage configuration unit package specified with a specific version while only one package version is available. Package Id: AppInstallerTest.TestValidManifest; Version: 1.0.0.0"));
    288         }
    289 
    290         /// <summary>
    291         /// No issues detected from WinGet resource units.
    292         /// </summary>
    293         [Test]
    294         public void ValidateWinGetDscResource_VersionSpecifiedWithUseLatest()
    295         {
    296             var result = TestCommon.RunAICLICommand(Command, TestCommon.GetTestDataFile("Configuration\\WinGetDscResourceValidate_VersionSpecifiedWithUseLatest.yml"), timeOut: 120000);
    297             Assert.AreEqual(Constants.ErrorCode.S_FALSE, result.ExitCode);
    298             Assert.True(result.StdOut.Contains("WinGetPackage declares both UseLatest and Version. Package Id: AppInstallerTest.TestExeInstaller"));
    299         }
    300     }
    301 }