Skip to content

Commit

Permalink
Added WinGetUtil E2E tests (#2542)
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelBawa-msft authored Sep 29, 2022
1 parent a394ea8 commit 6777a54
Show file tree
Hide file tree
Showing 18 changed files with 710 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/AppInstallerCLIE2ETests/AppInstallerCLIE2ETests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<ProjectReference Include="..\WindowsPackageManager\WindowsPackageManager.vcxproj">
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
<ProjectReference Include="..\WinGetUtil\WinGetUtil.vcxproj">
<ReferenceOutputAssembly>False</ReferenceOutputAssembly>
</ProjectReference>
</ItemGroup>

<ItemGroup>
Expand All @@ -55,5 +58,6 @@
<!-- Rename dll to align with the expected search pattern performed by CsWinRT -->
<Copy SourceFiles="$(TargetDir)..\Microsoft.Management.Deployment.InProc\Microsoft.Management.Deployment.InProc.dll" DestinationFiles="$(TargetDir)Microsoft.Management.Deployment.dll" />
<Copy SourceFiles="$(TargetDir)..\WindowsPackageManager\WindowsPackageManager.dll" DestinationFiles="$(TargetDir)WindowsPackageManager.dll" />
<Copy SourceFiles="$(TargetDir)..\WinGetUtil\WinGetUtil.dll" DestinationFiles="$(TargetDir)WinGetUtil.dll" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": "1.0",
"metadatas": [
{
"version": "1.0",
"productVersionMin": "1.0",
"productVersionMax": "1.0",
"metadata": [
{
"installerHash": "ABCD",
"submissionIdentifier": "1",
"AppsAndFeaturesEntries": [
{
"DisplayName": "Name",
"Publisher": "Publisher",
"DisplayVersion": "1.0",
"ProductCode": "{46210E3D-EBB3-43D4-B9BB-48A7DB0F9B93}",
"InstallerType": 3
}
]
}
]
},
{
"version": "1.0",
"productVersionMin": "1.0",
"productVersionMax": "1.0",
"metadata": [
{
"installerHash": "EFGH",
"submissionIdentifier": "2",
"AppsAndFeaturesEntries": [
{
"DisplayName": "Name",
"Publisher": "Publisher",
"DisplayVersion": "1.0",
"ProductCode": "{46210E3D-EBB3-43D4-B9BB-48A7DB0F9B93}",
"InstallerType": 3
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"version": "1.0",
"metadatas": [
{
"version": "1.0",
"productVersionMin": "1.0",
"productVersionMax": "1.0",
"metadata": [
{
"installerHash": "ABCD",
"submissionIdentifier": "1",
"AppsAndFeaturesEntries": [
{
"DisplayName": "Name",
"Publisher": "Publisher",
"DisplayVersion": "1.0",
"ProductCode": "{46210E3D-EBB3-43D4-B9BB-48A7DB0F9B93}",
"InstallerType": 3
}
]
}
]
},
{
"version": "1.0",
"productVersionMin": "1.0",
"productVersionMax": "1.0",
"metadata": [
{
"installerHash": "EFGH",
"submissionIdentifier": "1",
"AppsAndFeaturesEntries": [
{
"DisplayName": "Name",
"Publisher": "Publisher",
"DisplayVersion": "1.0",
"ProductCode": "{46210E3D-EBB3-43D4-B9BB-48A7DB0F9B93}",
"InstallerType": 3
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "1.0",
"supportedMetadataVersion": "1.0",
"submissionData": {
"submissionIdentifier": "1"
},
"packageData": {
"installerHash": "ABCD",
"DefaultLocale": {
"PackageLocale": "en-us",
"PackageName": "Name",
"Publisher": "Publisher"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Installers:
- Architecture: x86
InstallerSha256: 0000000000000000000000000000000000000000000000000000000000000000
InstallerType: exe
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
License: Test
ManifestType: merged
ManifestVersion: 1.1.0
MinimumOSVersion: 10.0.0.0
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageLocale: en-US
PackageName: AppInstallerTest
PackageVersion: 1.0.0.0
Publisher: AppInstallerTest
Tags:
- add
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Installers:
- Architecture: x86
InstallerSha256: 0000000000000000000000000000000000000000000000000000000000000000
InstallerType: exe
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
License: Test
ManifestType: merged
ManifestVersion: 1.1.0
MinimumOSVersion: 10.0.0.0
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageLocale: en-US
PackageName: AppInstallerTest
PackageVersion: 1.0.0.0
Publisher: AppInstallerTest
Tags:
- update
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageVersion: "1.0.0.0"
MinimumOSVersion: 10.0.0.0
Installers:
- Architecture: x86
InstallerUrl: https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe
InstallerType: nullsoft
InstallerSha256: 0000000000000000000000000000000000000000000000000000000000000000
ManifestType: installer
ManifestVersion: 1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageVersion: "1.0.0.0"
PackageLocale: en-US
Publisher: AppInstallerTest
License: Test
PackageName: AppInstallerTest
ShortDescription: WinGetUtilTest
ManifestType: defaultLocale
ManifestVersion: 1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageVersion: "1.0.0.0"
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.1.0
2 changes: 1 addition & 1 deletion src/AppInstallerCLIE2ETests/TestIndexSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static void SetupSourcePackage()
}

// Generate Index.db file using IndexCreationTool.exe
RunCommand(Path.Combine(indexCreationToolPath, "IndexCreationTool.exe"), $"-d {TestCommon.StaticFileRootPath}", indexDestPath);
RunCommand(Path.Combine(indexCreationToolPath, "IndexCreationTool.exe"), $"-d {TestCommon.StaticFileRootPath} -i {ManifestsName}", indexDestPath);

string packageDir = Path.Combine(TestCommon.StaticFileRootPath, PackageName);
string indexPackageDestPath = Path.Combine(TestCommon.StaticFileRootPath, Constants.IndexPackage);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using NUnit.Framework;

public class WinGetUtilCompareVersions
{
[Test]
// V1 = V2
[TestCase("1.0.0.0", "1.0.0.0", 0)]
[TestCase("1.0.0", "1.0.0.0", 0)]
[TestCase("1.0", "1.0.0.0", 0)]
[TestCase("1", "1.0.0.0", 0)]
// V1 > V2
[TestCase("1.0.0.1", "1.0.0.0", 1)]
[TestCase("1.0.1.0", "1.0.0.0", 1)]
[TestCase("1.1.0.0", "1.0.0.0", 1)]
[TestCase("2.0.0.0", "1.0.0.0", 1)]
// V1 < V2
[TestCase("1.0.0.0", "1.0.0.1", -1)]
[TestCase("1.0.0.0", "1.0.1.0", -1)]
[TestCase("1.0.0.0", "1.1.0.0", -1)]
[TestCase("1.0.0.0", "2.0.0.0", -1)]
public void WinGetUtil_CompareVersions(string version1, string version2, int expectedResult)
{
// Compare versions
WinGetUtilWrapper.WinGetCompareVersions(version1, version2, out int result);
Assert.AreEqual(expectedResult, result);
}
}
}
27 changes: 27 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilDownload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using System.IO;
using System.Linq;
using NUnit.Framework;

public class WinGetUtilDownload
{
[Test]
public void WinGetUtil_Download()
{
uint hashSize = 32;
byte[] sha256Hash = new byte[hashSize];
string installerUrl = @"https://localhost:5001/TestKit/AppInstallerTestExeInstaller/AppInstallerTestExeInstaller.exe";
string filePath = TestCommon.GetRandomTestFile(".exe");

// Download
WinGetUtilWrapper.WinGetDownload(installerUrl, filePath, sha256Hash, hashSize);

Assert.True(File.Exists(filePath));
Assert.False(sha256Hash.All(byteVal => byteVal == 0));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using Newtonsoft.Json;
using NUnit.Framework;
using System;
using System.IO;
using System.Runtime.InteropServices;

public class WinGetUtilInstallerMetadataCollection
{
[Test]
public void WinGetUtil_BeginCompleteInstallerMetadataCollection()
{
string logFilePath = TestCommon.GetRandomTestFile(".log");
string inputJson = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\Minimal.json");
string outputFilePath = TestCommon.GetRandomTestFile(".json");

WinGetUtilWrapper.WinGetBeginInstallerMetadataCollection(
inputJson,
logFilePath,
WinGetUtilWrapper.WinGetBeginInstallerMetadataCollectionOptions.WinGetBeginInstallerMetadataCollectionOption_InputIsFilePath,
out IntPtr collectionHandle);

Assert.AreNotEqual(IntPtr.Zero, collectionHandle);
Assert.True(File.Exists(logFilePath));

WinGetUtilWrapper.WinGetCompleteInstallerMetadataCollection(
collectionHandle,
outputFilePath,
WinGetUtilWrapper.WinGetCompleteInstallerMetadataCollectionOptions.WinGetCompleteInstallerMetadataCollectionOption_None);

string outputJson = File.ReadAllText(outputFilePath);
Assert.IsNotEmpty(JsonConvert.DeserializeObject(outputJson).ToString());
}

[Test]
public void WinGetUtil_MergeInstallerMetadata_Success()
{
string logFilePath = TestCommon.GetRandomTestFile(".log");
string inputJsonPath = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\MergeValid.json");
string inputJson = File.ReadAllText(inputJsonPath);

WinGetUtilWrapper.WinGetMergeInstallerMetadata(
inputJson,
out string outputJson,
0,
logFilePath,
WinGetUtilWrapper.WinGetMergeInstallerMetadataOptions.WinGetMergeInstallerMetadataOptions_None);

Assert.True(File.Exists(logFilePath));
Assert.IsNotEmpty(JsonConvert.DeserializeObject(outputJson).ToString());
}

[Test]
public void WinGetUtil_MergeInstallerMetadata_Fail_SubmissionMismatch()
{
string logFilePath = TestCommon.GetRandomTestFile(".log");
string inputJsonPath = TestCommon.GetTestDataFile(@"WinGetUtil\InstallerMetadata\MergeSubmissionMismatch.json");
string inputJson = File.ReadAllText(inputJsonPath);

Assert.Throws<COMException>(() =>
{
WinGetUtilWrapper.WinGetMergeInstallerMetadata(
inputJson,
out string outputJson,
0,
logFilePath,
WinGetUtilWrapper.WinGetMergeInstallerMetadataOptions.WinGetMergeInstallerMetadataOptions_None);
});

Assert.True(File.Exists(logFilePath));
}
}
}
24 changes: 24 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using System.IO;
using NUnit.Framework;

public class WinGetUtilLog
{
[Test]
public void WinGetUtil_Logging()
{
string filePath = TestCommon.GetRandomTestFile(".log");

// Init logging
WinGetUtilWrapper.WinGetLoggingInit(filePath);
Assert.True(File.Exists(filePath));

// Terminate logging
WinGetUtilWrapper.WinGetLoggingTerm(filePath);
}
}
}
Loading

0 comments on commit 6777a54

Please sign in to comment.