Пример #1
0
        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");
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        public void CreatePackageDepVersions()
        {
            var tmp  = Path.GetTempFileName();
            var tmp2 = Path.GetTempFileName();

            Directory.Move("Packages", "Packages2");
            try
            {
                {
                    PackageDef def = new PackageDef();
                    def.Name     = "test";
                    def.InfoLink = "a";
                    def.Date     = DateTime.Today;

                    def.AddFile(tmp);

                    var bs = PluginManager.GetSearcher().Assemblies.First(asm => asm.Name == "OpenTap.Plugins.BasicSteps");
                    def.Files[0].DependentAssemblies.Add(bs);

                    var searcher = new PluginSearcher();
                    searcher.Search(Directory.GetCurrentDirectory());
                    List <AssemblyData> assemblies = searcher.Assemblies.ToList();
                    def.findDependencies(new List <string>(), assemblies);

                    Assert.AreEqual(0, def.Dependencies.Count);
                    Assert.AreNotEqual(0, def.Files.Count);
                }

                {
                    PackageDef def = new PackageDef();

                    def.AddFile(tmp);

                    var bs = PluginManager.GetSearcher().Assemblies.First(asm => asm.Name == "OpenTap.Plugins.BasicSteps");
                    def.Files[0].DependentAssemblies.Add(bs);

                    var searcher = new PluginSearcher();
                    searcher.Search(Directory.GetCurrentDirectory());
                    List <AssemblyData> assemblies = searcher.Assemblies.ToList();
                    def.findDependencies(new List <string> {
                        "OpenTap"
                    }, assemblies);

                    Assert.AreEqual(0, def.Dependencies.Count);
                    Assert.AreNotEqual(1, def.Files.Count);
                }
            }
            finally
            {
                if (Directory.Exists("Packages"))
                {
                    Directory.Delete("Packages", true);
                }
                Directory.Move("Packages2", "Packages");
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        [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);
                }
            }
        }
Пример #9
0
        public void CreatePackageDepReuse()
        {
            if (Directory.Exists("Packages2"))
            {
                Directory.Delete("Packages2", true);
            }

            Directory.Move("Packages", "Packages2");
            File.Copy("Packages2/DependencyTest.dll", "DependencyTest.dll", true);

            try
            {
                Directory.CreateDirectory("Packages");

                {
                    PackageDef def = new PackageDef()
                    {
                        Name = "pkg1", Version = SemanticVersion.Parse("1.2")
                    };
                    def.AddFile("OpenTap.dll");
                    Directory.CreateDirectory("Packages/pkg1");
                    using (var f = File.OpenWrite("Packages/pkg1/package.xml")) def.SaveTo(f);
                }

                {
                    PackageDef def = new PackageDef()
                    {
                        Name = "gui", Version = SemanticVersion.Parse("1.2")
                    };
                    def.AddFile("Keysight.OpenTap.Wpf.dll");
                    Directory.CreateDirectory("Packages/gui");
                    using (var f = File.OpenWrite("Packages/gui/package.xml")) def.SaveTo(f);
                }

                {
                    PackageDef def = new PackageDef()
                    {
                        Name = "rv", Version = SemanticVersion.Parse("1.2")
                    };
                    def.AddFile("Keysight.OpenTap.Wpf.dll");
                    Directory.CreateDirectory("Packages/rv");
                    using (var f = File.OpenWrite("Packages/rv/package.xml")) def.SaveTo(f);
                }

                {
                    PackageDef def = new PackageDef();
                    def.Name     = "test";
                    def.InfoLink = "a";
                    def.Date     = DateTime.Today;

                    def.Dependencies.Add(new PackageDependency("rv", VersionSpecifier.Parse("1.2")));

                    def.AddFile("DependencyTest.dll");
                    def.Files[0].DependentAssemblies.AddRange(PluginManager.GetSearcher().Assemblies.First(f => f.Name == "DependencyTest").References);

                    var searcher = new PluginSearcher();
                    searcher.Search(Directory.GetCurrentDirectory());
                    List <AssemblyData> assemblies = searcher.Assemblies.ToList();
                    def.findDependencies(new List <string>(), assemblies);

                    //Assert.AreEqual(3, def.Dependencies.Count);
                    Assert.IsTrue(def.Dependencies.Any(d => d.Name == "rv"));
                    Assert.IsTrue(def.Dependencies.Any(d => d.Name == "pkg1"));
                }

                {
                    PackageDef def = new PackageDef();
                    def.Name     = "test";
                    def.InfoLink = "a";
                    def.Date     = DateTime.Today;

                    def.Dependencies.Add(new PackageDependency("gui", VersionSpecifier.Parse("1.2")));

                    def.AddFile("DependencyTest.dll");
                    def.Files[0].DependentAssemblies.AddRange(PluginManager.GetSearcher().Assemblies.First(f => f.Name == "DependencyTest").References);

                    var searcher = new PluginSearcher();
                    searcher.Search(Directory.GetCurrentDirectory());
                    List <AssemblyData> assemblies = searcher.Assemblies.ToList();
                    def.findDependencies(new List <string>(), assemblies);

                    //Assert.AreEqual(2, def.Dependencies.Count);
                    Assert.IsTrue(def.Dependencies.Any(d => d.Name == "gui"));
                    Assert.IsTrue(def.Dependencies.Any(d => d.Name == "pkg1"));
                }
            }
            finally
            {
                if (Directory.Exists("Packages"))
                {
                    Directory.Delete("Packages", true);
                }
                Directory.Move("Packages2", "Packages");
            }
        }