ValidateCommand.cs (6887B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="ValidateCommand.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 /// Test validate command. 14 /// </summary> 15 public class ValidateCommand : BaseCommand 16 { 17 /// <summary> 18 /// Test validate manifest. 19 /// </summary> 20 [Test] 21 public void ValidateManifest() 22 { 23 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestValidManifest.yaml")); 24 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 25 Assert.True(result.StdOut.Contains("Manifest validation succeeded.")); 26 } 27 28 /// <summary> 29 /// Test validate manifest with extended characters. 30 /// </summary> 31 [Test] 32 public void ValidateManifestWithExtendedCharacter() 33 { 34 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TëstExeInstaller.yaml")); 35 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 36 Assert.True(result.StdOut.Contains("Manifest validation succeeded.")); 37 } 38 39 /// <summary> 40 /// Test validate invalid manifest. 41 /// </summary> 42 [Test] 43 public void ValidateInvalidManifest() 44 { 45 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestInvalidManifest.yaml")); 46 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_FAILURE, result.ExitCode); 47 Assert.True(result.StdOut.Contains("Manifest validation failed.")); 48 } 49 50 /// <summary> 51 /// Test validate manifest with warnings. 52 /// </summary> 53 [Test] 54 public void ValidateManifestWithWarnings() 55 { 56 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifest.yaml")); 57 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 58 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 59 } 60 61 /// <summary> 62 /// Test validate manifest with warnings suppressed. 63 /// </summary> 64 [Test] 65 public void ValidateManifestSuppressWarnings() 66 { 67 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifest.yaml") + " --ignore-warnings"); 68 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 69 Assert.False(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 70 Assert.True(result.StdOut.Contains("Manifest validation succeeded.")); 71 } 72 73 /// <summary> 74 /// Test validate manifest that doesn't exist. 75 /// </summary> 76 [Test] 77 public void ValidateManifestDoesNotExist() 78 { 79 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\DoesNotExist")); 80 Assert.AreEqual(Constants.ErrorCode.ERROR_PATH_NOT_FOUND, result.ExitCode); 81 Assert.True(result.StdOut.Contains("Path does not exist")); 82 } 83 84 /// <summary> 85 /// Test validate manifest with invalid schema and expect warnings. 86 /// </summary> 87 [Test] 88 public void ValidateManifestV1_10_SchemaHeaderExpectWarnings() 89 { 90 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifestV1_10-SchemaHeaderNotFound.yaml")); 91 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 92 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 93 Assert.True(result.StdOut.Contains("Manifest Warning: Schema header not found.")); 94 95 result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifestV1_10-SchemaHeaderInvalid.yaml")); 96 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 97 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 98 Assert.True(result.StdOut.Contains("Manifest Warning: The schema header is invalid. Please verify that the schema header is present and formatted correctly.")); 99 100 result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifestV1_10-SchemaHeaderURLPatternMismatch.yaml")); 101 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 102 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 103 Assert.True(result.StdOut.Contains("Manifest Warning: The schema header URL does not match the expected pattern")); 104 105 result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifestV1_10-SchemaHeaderManifestTypeMismatch.yaml")); 106 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 107 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 108 Assert.True(result.StdOut.Contains("Manifest Warning: The manifest type in the schema header does not match the ManifestType property value in the manifest.")); 109 110 result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestWarningManifestV1_10-SchemaHeaderVersionMismatch.yaml")); 111 Assert.AreEqual(Constants.ErrorCode.ERROR_MANIFEST_VALIDATION_WARNING, result.ExitCode); 112 Assert.True(result.StdOut.Contains("Manifest validation succeeded with warnings.")); 113 Assert.True(result.StdOut.Contains("Manifest Warning: The manifest version in the schema header does not match the ManifestVersion property value in the manifest.")); 114 } 115 116 /// <summary> 117 /// Test validate manifest with valid schema header. 118 /// </summary> 119 [Test] 120 public void ValidateManifestV1_10_SchemaHeaderExpectNoWarning() 121 { 122 var result = TestCommon.RunAICLICommand("validate", TestCommon.GetTestDataFile("Manifests\\TestGoodManifestV1_10-SchemaHeader.yaml")); 123 Assert.AreEqual(Constants.ErrorCode.S_OK, result.ExitCode); 124 } 125 } 126 }