Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WinGetUtil E2E tests #2542

Merged
merged 7 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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: exe
InstallerSha256: 0000000000000000000000000000000000000000000000000000000000000000
ManifestType: installer
ManifestVersion: 1.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PackageIdentifier: AppInstallerTest.WinGetUtilTest
PackageVersion: "1.0.0.0"
PackageLocale: en-US
Publisher: AppInstallerTest
License: Test
PackageName: AppInstallerTest
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,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using System;
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
IntPtr hresult = WinGetUtilWrapper.WinGetCompareVersions(version1, version2, out int result);

Assert.AreEqual(IntPtr.Zero, hresult);
Assert.AreEqual(expectedResult, result);
}
}
}
29 changes: 29 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilDownload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace AppInstallerCLIE2ETests.WinGetUtil
{
using System;
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
IntPtr hresult = WinGetUtilWrapper.WinGetDownload(installerUrl, filePath, sha256Hash, hashSize);

Assert.AreEqual(IntPtr.Zero, hresult);
Assert.True(File.Exists(filePath));
Assert.False(sha256Hash.All(byteVal => byteVal == 0));
}
}
}
30 changes: 30 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

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

// Init logging
hresult = WinGetUtilWrapper.WinGetLoggingInit(filePath);

Assert.AreEqual(IntPtr.Zero, hresult);
Assert.True(File.Exists(filePath));

// Terminate logging
hresult = WinGetUtilWrapper.WinGetLoggingTerm(filePath);

Assert.AreEqual(IntPtr.Zero, hresult);
}
}
}
70 changes: 70 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

public class WinGetUtilManifest
{
IntPtr indexHandle;

[SetUp]
public void SetUp()
{
var sqliteFile = TestCommon.GetRandomTestFile(".db");
uint majorVersion = 1;
uint minorVersion = 2;
WinGetUtilWrapper.WinGetSQLiteIndexCreate(sqliteFile, majorVersion, minorVersion, out this.indexHandle); ;
}

[TearDown]
public void TearDown()
{
WinGetUtilWrapper.WinGetSQLiteIndexClose(this.indexHandle);
}

AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
[Test]
public void WinGetUtil_ValidateManifest()
{
string manifestsDir = TestCommon.GetTestDataFile(@"WinGetUtil\Manifests\Unmerged\ValidateManifest");
string mergedManifestPath = TestCommon.GetRandomTestFile(".yaml");
IntPtr hresult;

// Create manifest
hresult = WinGetUtilWrapper.WinGetCreateManifest(
manifestsDir,
out bool succeeded,
out IntPtr manifestHandle,
out string createFailureMessage,
mergedManifestPath,
WinGetUtilWrapper.CreateManifestOption.NoValidation);

Assert.AreEqual(IntPtr.Zero, hresult);
Assert.True(succeeded);
Assert.AreNotEqual(IntPtr.Zero, manifestHandle);
Assert.IsNull(createFailureMessage);
Assert.True(File.Exists(mergedManifestPath));

// Validate manifest
hresult = WinGetUtilWrapper.WinGetValidateManifestV3(
manifestHandle,
indexHandle,
out WinGetUtilWrapper.ValidateManifestResultCode resultCode,
out string validateFailureMessage,
WinGetUtilWrapper.ValidateManifestOptionV2.ArpVersionValidation,
WinGetUtilWrapper.ValidateManifestOperationType.Add);

Assert.AreEqual(IntPtr.Zero, hresult);
Assert.AreEqual(WinGetUtilWrapper.ValidateManifestResultCode.Success, resultCode);
Assert.IsEmpty(validateFailureMessage);

// Close manifest
hresult = WinGetUtilWrapper.WinGetCloseManifest(manifestHandle);

Assert.AreEqual(IntPtr.Zero, hresult);
}
}
}
Loading