public void NoDowngradeInstallTest() { var installation = new Installation(Directory.GetCurrentDirectory()); var package = new PackageDef(); package.Name = "NoDowngradeTest"; package.Version = SemanticVersion.Parse("1.0.1"); var newPath = DummyPackageGenerator.GeneratePackage(package); package.Version = SemanticVersion.Parse("1.0.0"); var oldPath = DummyPackageGenerator.GeneratePackage(package); // Install new version var output = RunPackageCli($"install {newPath}", out int exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("installed"), "NoDowngradeTest package was not installed."); var installedVersion = installation.GetPackages()?.FirstOrDefault(p => p.Name == "NoDowngradeTest")?.Version; Assert.IsTrue(installedVersion == SemanticVersion.Parse("1.0.1"), $"NoDowngradeTest installed the wrong version: '{installedVersion}'."); // Install older version with --no-downgrade option. This should not install the old version. output = RunPackageCli($"install --no-downgrade {oldPath}", out exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("already installed"), "NoDowngradeTest package was not installed."); installedVersion = installation.GetPackages()?.FirstOrDefault(p => p.Name == "NoDowngradeTest")?.Version; Assert.IsTrue(installedVersion == SemanticVersion.Parse("1.0.1"), $"NoDowngradeTest failed to skip the install: '{installedVersion}'."); // Install older version without --no-downgrade option. This should install the old version. output = RunPackageCli($"install {oldPath}", out exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("installed"), "NoDowngradeTest package was not installed."); installedVersion = installation.GetPackages()?.FirstOrDefault(p => p.Name == "NoDowngradeTest")?.Version; Assert.IsTrue(installedVersion == SemanticVersion.Parse("1.0.0"), $"NoDowngradeTest failed to install the old version: '{installedVersion}'."); }
public void SkipInstallExactVersionAlreadyInstalledTest() { var package = new PackageDef(); package.Name = "ExactVersionTest"; package.Version = SemanticVersion.Parse("1.0.1"); package.OS = "Windows,Linux"; var path = DummyPackageGenerator.GeneratePackage(package); // Install var output = RunPackageCli($"install {path}", out int exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("installed"), "ExactVersionTest package was not installed."); // Install the exact same version. This should skip. output = RunPackageCli($"install {package.Name} --version 1.0.1", out exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("already installed"), "ExactVersionTest package install was not skipped."); // Install the exact same version with --force. This should not skip. output = RunPackageCli($"install {package.Name} --version 1.0.1 -f", out exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("already installed") == false, "ExactVersionTest package install with -f was skipped."); // Install the exact same version from file. This should not skip. output = RunPackageCli($"install {path}", out exitCode); Assert.IsTrue(exitCode == 0 && output.ToLower().Contains("already installed") == false, "ExactVersionTest package install was skipped."); }
public void InstallLocalFile() { var package = new PackageDef(); package.Name = "Dummy Something"; package.Version = SemanticVersion.Parse("1.0.0"); package.Description = "Cached version"; var file = DummyPackageGenerator.GeneratePackage(package); if (File.Exists(Path.Combine("PackageCache", file))) { File.Delete(Path.Combine("PackageCache", file)); } File.Move(file, Path.Combine("PackageCache", file)); package.Description = "Right version"; var file2 = DummyPackageGenerator.GeneratePackage(package); var result = RunPackageCli("install -v -f \"" + Path.GetFullPath(file2) + "\"", out int exitcode); Assert.IsTrue(result.ToLower().Contains("installed")); Assert.IsTrue(result.ToLower().Contains("downloading file without searching")); var installedPackage = new Installation(Directory.GetCurrentDirectory()).GetPackages().FirstOrDefault(p => p.Name == package.Name); Assert.IsNotNull(installedPackage, "Package was not installed"); Assert.AreEqual(package.Description, installedPackage.Description); }
public void InstallFileWithMissingDependencyTest() { var def = new PackageDef(); def.Name = "Dummy2"; def.OS = "Windows,Linux"; def.Version = SemanticVersion.Parse("1.0"); def.AddFile("Dummy.txt"); def.Dependencies.Add(new PackageDependency("Missing", VersionSpecifier.Parse("1.0"))); DummyPackageGenerator.InstallDummyPackage("Missing"); string pkgFile = DummyPackageGenerator.GeneratePackage(def); DummyPackageGenerator.UninstallDummyPackage("Missing"); try { int exitCode; string output = RunPackageCli("install Dummy2 -y", out exitCode); //Assert.AreNotEqual(0, exitCode, "Unexpected exit code"); StringAssert.Contains("'Missing' with a version compatible with 1.0", output); } finally { File.Delete(pkgFile); } }
public void UninstallFirstTest() { var dep0Def = new PackageDef(); dep0Def.Name = "UninstallPackage"; dep0Def.Version = SemanticVersion.Parse("0.1"); dep0Def.AddFile("UninstallText.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(dep0Def); var dep1Def = new PackageDef(); dep1Def.Name = "UninstallPackage"; dep1Def.Version = SemanticVersion.Parse("0.2"); dep1Def.AddFile("SubDir/UninstallText.txt"); Directory.CreateDirectory("SubDir"); string dep1File = DummyPackageGenerator.GeneratePackage(dep1Def); int exitCode; string output = RunPackageCli("install " + dep0File, out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code1: " + output); Assert.IsTrue(File.Exists("UninstallText.txt"), "File0 should exist"); output = RunPackageCli("install " + dep1File, out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code2: " + output); Assert.IsTrue(File.Exists("SubDir/UninstallText.txt"), "File1 should exist"); Assert.IsFalse(File.Exists("UninstallText.txt"), "File0 should not exist"); }
public void CyclicDependenciesTest() { DummyPackageGenerator.InstallDummyPackage(); // We need to have "Dummy" installed before we can create a package that depends on it. var depDef = new PackageDef(); depDef.Name = "Dependency"; depDef.OS = "Windows,Linux"; depDef.Version = SemanticVersion.Parse("1.0"); depDef.AddFile("Dependency.txt"); depDef.Dependencies.Add(new PackageDependency("Dummy", VersionSpecifier.Parse("1.0"))); string dep0File = DummyPackageGenerator.GeneratePackage(depDef); DummyPackageGenerator.UninstallDummyPackage(); DummyPackageGenerator.InstallDummyPackage("Dependency"); var dummyDef = new PackageDef(); dummyDef.Name = "Dummy"; dummyDef.OS = "Windows,Linux"; dummyDef.Version = SemanticVersion.Parse("1.0"); dummyDef.AddFile("Dummy.txt"); dummyDef.Dependencies.Add(new PackageDependency("Dependency", VersionSpecifier.Parse("1.0"))); string dummyFile = DummyPackageGenerator.GeneratePackage(dummyDef); DummyPackageGenerator.UninstallDummyPackage("Dependency"); try { if (File.Exists("Dependency.txt")) { File.Delete("Dependency.txt"); } if (File.Exists("Dummy.txt")) { File.Delete("Dummy.txt"); } int exitCode; string output = RunPackageCli("install Dummy -y", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code.\r\n" + output); StringAssert.Contains("Dummy", output); StringAssert.Contains("Dependency", output); Assert.IsTrue(File.Exists("Dependency.txt")); Assert.IsTrue(File.Exists("Dummy.txt")); } finally { PluginInstaller.Uninstall(dummyDef, Directory.GetCurrentDirectory()); PluginInstaller.Uninstall(depDef, Directory.GetCurrentDirectory()); File.Delete(dep0File); File.Delete(dummyFile); } }
public void UpgradeDependencyTest() { var dep0Def = new PackageDef(); dep0Def.Name = "Dependency"; dep0Def.Version = SemanticVersion.Parse("0.1"); dep0Def.AddFile("Dependency0.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(dep0Def); var dep1Def = new PackageDef(); dep1Def.Name = "Dependency"; dep1Def.Version = SemanticVersion.Parse("1.0"); dep1Def.AddFile("Dependency1.txt"); string dep1File = DummyPackageGenerator.GeneratePackage(dep1Def); var dummyDef = new PackageDef(); dummyDef.Name = "Dummy"; dummyDef.Version = SemanticVersion.Parse("1.0"); dummyDef.AddFile("Dummy.txt"); dummyDef.Dependencies.Add(new PackageDependency("Dependency", VersionSpecifier.Parse("1.0"))); DummyPackageGenerator.InstallDummyPackage("Dependency"); string dummyFile = DummyPackageGenerator.GeneratePackage(dummyDef); DummyPackageGenerator.UninstallDummyPackage("Dependency"); try { int exitCode; string output = RunPackageCli("install " + dep0File + " --force", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code"); output = RunPackageCli("install Dummy -y", out exitCode); Assert.AreEqual(0, exitCode, "Unexpected exit code"); //StringAssert.Contains("upgrading", output); Assert.IsTrue(File.Exists("Dependency1.txt")); } finally { PluginInstaller.Uninstall(dummyDef, Directory.GetCurrentDirectory()); PluginInstaller.Uninstall(dep1Def, Directory.GetCurrentDirectory()); File.Delete(dep0File); File.Delete(dep1File); File.Delete(dummyFile); } }
public void CheckInvalidPackageName() { // Check if name contains invalid character try { DummyPackageGenerator.GeneratePackage(new PackageDef() { Name = "Op/en:T\\AP" }); Assert.Fail("Path contains invalid character"); } catch (Exception e) { Console.WriteLine(e.Message); Assert.True(e.Message.Contains("invalid file path characters")); } }
public void InstallOutsideTapDirInSubDir() { var depDef = new PackageDef(); depDef.Name = "Pkg1"; depDef.Version = SemanticVersion.Parse("1.0"); depDef.AddFile("Dependency.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(depDef); string tempFn = Path.Combine(Path.GetTempPath(), Path.GetFileName(dep0File)); if (File.Exists(tempFn)) { File.Delete(tempFn); } File.Move(dep0File, tempFn); string testDir = Path.Combine(Path.GetTempPath(), "lolDir"); try { if (File.Exists("Dependency.txt")) { File.Delete("Dependency.txt"); } int exitCode; Directory.CreateDirectory(testDir); string output = RunPackageCli($"install --target {testDir} {Path.GetFileName(tempFn)}", out exitCode, Path.GetDirectoryName(tempFn)); Assert.AreEqual(0, exitCode, "Unexpected exit code"); StringAssert.Contains("Installed Pkg1", output); Assert.IsTrue(File.Exists(Path.Combine(testDir, "Dependency.txt"))); } finally { File.Delete(dep0File); File.Delete(tempFn); Directory.Delete(testDir, true); } }
public void InstallOutsideTapDir() { var depDef = new PackageDef(); depDef.Name = "Pkg1"; depDef.Version = SemanticVersion.Parse("1.0"); depDef.AddFile("Dependency.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(depDef); string tempFn = Path.Combine(Path.GetTempPath(), Path.GetFileName(dep0File)); if (File.Exists(tempFn)) { File.Delete(tempFn); } File.Move(dep0File, tempFn); try { if (File.Exists("Dependency.txt")) { File.Delete("Dependency.txt"); } int exitCode; string output = RunPackageCli("install " + Path.GetFileName(tempFn), out exitCode, Path.GetDirectoryName(tempFn)); Assert.AreEqual(0, exitCode, "Unexpected exit code"); StringAssert.Contains("Installed Pkg1", output); Assert.IsTrue(File.Exists("Dependency.txt")); PluginInstaller.Uninstall(depDef, Directory.GetCurrentDirectory()); } finally { File.Delete(dep0File); File.Delete(tempFn); } }
[TestCase(false, true, null)] // tap package download pkg -r /tmp public void DownloadTest(bool useOut, bool useRepo, string outFileName) { var depDef = new PackageDef { Name = "Pkg1", Version = SemanticVersion.Parse("1.0"), OS = "Windows,Linux" }; depDef.AddFile("Dependency.txt"); string dep0File = DummyPackageGenerator.GeneratePackage(depDef); string tempFn = Path.Combine(Path.GetTempPath(), Path.GetFileName(dep0File)); if (File.Exists(tempFn)) { File.Delete(tempFn); } File.Move(dep0File, tempFn); string outArg = Path.Combine(Path.GetTempPath(), "Nested", "TargetDir" + Path.DirectorySeparatorChar); if (outFileName != null) { outArg = Path.Combine(outArg, outFileName); } string targetFile; // Expected output path differs depending on whether or not we specify --out if (useOut && outFileName == null) { targetFile = Path.GetFullPath(Path.Combine(outArg, PackageActionHelpers.GetQualifiedFileName(depDef))); } else if (useOut && outFileName != null) { targetFile = Path.GetFullPath(outArg); } else { targetFile = Path.Combine(Path.GetDirectoryName(typeof(Package.PackageDef).Assembly.Location), PackageActionHelpers.GetQualifiedFileName(depDef)); } try { var args = $"download "; if (useOut) { args += $" --out {outArg} "; } if (useRepo) { args += $" {depDef.Name} -r {Path.GetDirectoryName(tempFn)} "; } else { args += $" {Path.GetFileName(tempFn)} "; } string output = RunPackageCli(args, out var exitCode, Path.GetDirectoryName(tempFn)); Assert.AreEqual(0, exitCode, "Unexpected exit code"); StringAssert.Contains($@"Downloaded '{depDef.Name}' to '{targetFile}'.", output); Assert.IsTrue(File.Exists(targetFile)); } finally { File.Delete(dep0File); File.Delete(tempFn); if (useOut && outFileName == null) { Directory.Delete(outArg, true); } else { File.Delete(targetFile); } } }