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 5 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,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));
}
}
}
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);
}
}
}
81 changes: 81 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilManifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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()
{
this.indexHandle = IntPtr.Zero;
var sqliteFile = TestCommon.GetRandomTestFile(".db");
uint majorVersion = 1;
uint minorVersion = 2;
WinGetUtilWrapper.WinGetSQLiteIndexCreate(sqliteFile, majorVersion, minorVersion, out this.indexHandle); ;
}

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

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

Assert.False(succeeded);
Assert.AreEqual(IntPtr.Zero, manifestHandle);
Assert.IsNotEmpty(createFailureMessage);
Assert.True(File.Exists(mergedManifestPath));
}

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

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

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

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

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

// Close manifest
WinGetUtilWrapper.WinGetCloseManifest(manifestHandle);
}
}
}
142 changes: 142 additions & 0 deletions src/AppInstallerCLIE2ETests/WinGetUtil/WinGetUtilSQLiteIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

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

public class WinGetUtilSQLiteIndex
{
private string sqlitePath;
private readonly uint majorVersion = 1;
private readonly uint minorVersion = 2;

// Manifest example 1
private readonly string addManifestsFile_1 = TestCommon.GetTestDataFile(@"WinGetUtil\Manifests\Merged\WinGetUtilTest.Add.yaml");
private readonly string updateManifestsFile_1 = TestCommon.GetTestDataFile(@"WinGetUtil\Manifests\Merged\WinGetUtilTest.Update.yaml");
private readonly string relativePath_1 = @"manifests\a\AppInstallerTest\WinGetUtilTest\1.0.0.0\WinGetTest.yaml";

[SetUp]
public void SetUp()
{
this.sqlitePath = TestCommon.GetRandomTestFile(".sql");
}

[Test]
public void WinGetUtil_SQLiteIndex_AddManifest()
{
SQLiteIndex((indexHandle) =>
{
// Add manifest
WinGetUtilWrapper.WinGetSQLiteIndexAddManifest(indexHandle, addManifestsFile_1, relativePath_1);
});
}

[Test]
public void WinGetUtil_SQLiteIndex_UpdateManifest_Success()
{
SQLiteIndex((indexHandle) =>
{
// Add manifest
WinGetUtilWrapper.WinGetSQLiteIndexAddManifest(indexHandle, addManifestsFile_1, relativePath_1);

// Update manifest
WinGetUtilWrapper.WinGetSQLiteIndexUpdateManifest(indexHandle, updateManifestsFile_1, relativePath_1, out bool indexModified);
Assert.True(indexModified);
});
}

[Test]
public void WinGetUtil_SQLiteIndex_UpdateManifest_Fail_NotFound()
{
SQLiteIndex((indexHandle) =>
{
// Update non-existing manifest
Assert.Throws<COMException>(() =>
{
WinGetUtilWrapper.WinGetSQLiteIndexUpdateManifest(indexHandle, updateManifestsFile_1, relativePath_1, out bool indexModified);
});
});
}

[Test]
public void WinGetUtil_SQLiteIndex_RemoveManifest_Success()
{
SQLiteIndex((indexHandle) =>
{
// Add manifest
WinGetUtilWrapper.WinGetSQLiteIndexAddManifest(indexHandle, addManifestsFile_1, relativePath_1);

// Remove manifest
WinGetUtilWrapper.WinGetSQLiteIndexRemoveManifest(indexHandle, addManifestsFile_1, relativePath_1);
});
}

[Test]
public void WinGetUtil_SQLiteIndex_RemoveManifest_Fail_NotFound()
{
SQLiteIndex((indexHandle) =>
{
// Remove non-existing manifest
Assert.Throws<COMException>(() =>
{
WinGetUtilWrapper.WinGetSQLiteIndexRemoveManifest(indexHandle, addManifestsFile_1, relativePath_1);
});
});
}

[Test]
public void WinGetUtil_SQLiteIndex_OpenClose()
{
SQLiteIndex((_) =>
{
// Open
WinGetUtilWrapper.WinGetSQLiteIndexOpen(sqlitePath, out IntPtr indexHandle);

// Add manifest
WinGetUtilWrapper.WinGetSQLiteIndexAddManifest(indexHandle, addManifestsFile_1, relativePath_1);

// Close
WinGetUtilWrapper.WinGetSQLiteIndexClose(indexHandle);
});
}

[Test]
public void WinGetUtil_SQLiteIndex_CheckConsistency()
{
SQLiteIndex((indexHandle) =>
{
// Add manifest
WinGetUtilWrapper.WinGetSQLiteIndexAddManifest(indexHandle, addManifestsFile_1, relativePath_1);

// Prepare for packaging
WinGetUtilWrapper.WinGetSQLiteIndexPrepareForPackaging(indexHandle);

// Check consistency
WinGetUtilWrapper.WinGetSQLiteIndexCheckConsistency(indexHandle, out bool succeeded);
Assert.True(succeeded);
});
}

/// <summary>
/// Create and close an sqlite index file.
/// </summary>
/// <param name="Execute">Function to execute.</param>
private void SQLiteIndex(Action<IntPtr> Execute)
{
// Create
WinGetUtilWrapper.WinGetSQLiteIndexCreate(sqlitePath, majorVersion, minorVersion, out IntPtr indexHandle);
Assert.True(File.Exists(sqlitePath));
Assert.AreNotEqual(IntPtr.Zero, indexHandle);

// Execute provided function
Execute(indexHandle);

// Close
WinGetUtilWrapper.WinGetSQLiteIndexClose(indexHandle);
}
}
}
Loading