Exemplo n.º 1
0
        public async Task GivenThatTheFeedHasMissingPackagesVerifyExistingPackagesAreDownloaded()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var cache2 = new LocalCache())
                            using (var outputFolder = new TestFolder())
                            {
                                var log         = new TestLogger();
                                var fileSystem  = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                                var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));
                                var settings    = new LocalSettings();

                                await InitCommand.RunAsync(settings, fileSystem, log);

                                var expected = new List <string>();

                                for (var i = 0; i < 100; i++)
                                {
                                    var package = new TestNupkg("a", $"{i}.0.0");
                                    package.Save(packagesFolder);

                                    if (i != 50)
                                    {
                                        expected.Add($"a.{i}.0.0.nupkg");
                                    }
                                }

                                await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log);

                                var root = new DirectoryInfo(target);
                                foreach (var file in root.GetFiles("a.50.0.0*", SearchOption.AllDirectories))
                                {
                                    // Corrupt the feed
                                    file.Delete();
                                }

                                var success = await DownloadCommand.RunAsync(settings, fileSystem2, outputFolder, false, log);

                                var fileNames = Directory.GetFiles(outputFolder, "*.nupkg", SearchOption.AllDirectories)
                                                .Select(e => Path.GetFileName(e))
                                                .OrderBy(e => e, StringComparer.OrdinalIgnoreCase)
                                                .ToArray();

                                success.ShouldBeEquivalentTo(false, "the feed is not valid");

                                fileNames.ShouldBeEquivalentTo(expected, "all files but the deleted one");

                                log.GetMessages().Should().NotContain("The feed does not contain any packages");
                                log.GetMessages().Should().Contain("Failed to download all packages!");

                                foreach (var file in expected)
                                {
                                    log.GetMessages().Should().Contain(file);
                                }
                            }
        }
Exemplo n.º 2
0
        public async Task AddRemove_AddAndDeletePackagesAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage1 = new TestNupkg("packageA", "1.0.0");
                        var testPackage2 = new TestNupkg("packageA", "2.0.0");
                        var testPackage3 = new TestNupkg("packageB", "2.0.0");

                        var zipFile1 = testPackage1.Save(packagesFolder.Root);
                        var zipFile2 = testPackage2.Save(packagesFolder.Root);
                        var zipFile3 = testPackage3.Save(packagesFolder.Root);

                        var toDelete = new List <PackageIdentity>()
                        {
                            new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), new PackageIdentity("packageB", NuGetVersion.Parse("2.0.0"))
                        };

                        // Act
                        // run commands
                        await InitCommand.InitAsync(context);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log);

                        await DeleteCommand.DeletePackagesAsync(context.LocalSettings, context.Source, toDelete, string.Empty, false, context.Log);

                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        // read outputs
                        var packageIndex  = new PackageIndex(context);
                        var indexPackages = await packageIndex.GetPackagesAsync();

                        // Assert
                        Assert.True(validateOutput);
                        Assert.Equal(1, indexPackages.Count);
                        Assert.Equal("packageA", indexPackages.First().Id);
                        Assert.Equal("2.0.0", indexPackages.First().Version.ToNormalizedString());
                    }
        }
Exemplo n.º 3
0
        public async Task BadgeFile_VerifyBadgesDifferentVersions()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                BadgesEnabled = true
                            }
                        };

                        // Initial packages
                        var identities = new HashSet <PackageIdentity>()
                        {
                            new PackageIdentity("a", NuGetVersion.Parse("3.0.0-a")),
                            new PackageIdentity("a", NuGetVersion.Parse("2.0.0"))
                        };

                        foreach (var id in identities)
                        {
                            var testPackage = new TestNupkg(id.Id, id.Version.ToFullString());
                            var zipFile     = testPackage.Save(packagesFolder.Root);
                        }

                        // Push
                        await InitCommand.InitAsync(context);

                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log);

                        // Validate
                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        validateOutput.Should().BeTrue();

                        // read output
                        var stablePathJson = Path.Combine(target.Root, "badges/v/a.json");
                        var prePathJson    = Path.Combine(target.Root, "badges/vpre/a.json");
                        File.Exists(stablePathJson).Should().BeTrue();
                        File.Exists(prePathJson).Should().BeTrue();

                        File.ReadAllText(stablePathJson).Should().Contain("2.0.0");
                        File.ReadAllText(prePathJson).Should().Contain("3.0.0-a");
                    }
        }
Exemplo n.º 4
0
        public void SubFeed_VerifySubFeedPathMustBeOnPath()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var root       = UriUtility.CreateUri(target.Root);
                    var fileSystem = new PhysicalFileSystem(cache, root, root, feedSubPath: "feedA");

                    Assert.Throws <ArgumentException>(() => SourceUtility.ValidateFileSystem(fileSystem));
                }
        }
Exemplo n.º 5
0
        public async Task GivenInitVerifyBasicOutputs()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    // Arrange
                    var log        = new TestLogger();
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                    var settings   = new LocalSettings();

                    var indexJsonOutput    = new FileInfo(Path.Combine(target.Root, "index.json"));
                    var settingsOutput     = new FileInfo(Path.Combine(target.Root, "sleet.settings.json"));
                    var autoCompleteOutput = new FileInfo(Path.Combine(target.Root, "autocomplete", "query"));
                    var catalogOutput      = new FileInfo(Path.Combine(target.Root, "catalog", "index.json"));
                    var searchOutput       = new FileInfo(Path.Combine(target.Root, "search", "query"));
                    var packageIndexOutput = new FileInfo(Path.Combine(target.Root, "sleet.packageindex.json"));
                    var symbolsIndexOutput = new FileInfo(Path.Combine(target.Root, "symbols", "packages", "index.json"));

                    // Act
                    var success = await InitCommand.RunAsync(settings, fileSystem, enableCatalog : true, enableSymbols : true, log : log, token : CancellationToken.None);

                    var rootFile = fileSystem.Get("index.json");
                    var rootJson = await rootFile.GetJson(log, CancellationToken.None);

                    success &= await FeedSettingsCommand.RunAsync(
                        settings,
                        fileSystem,
                        unsetAll : false,
                        getAll : true,
                        getSettings : new string[] { },
                        unsetSettings : new string[] { },
                        setSettings : new string[] { },
                        log : log,
                        token : CancellationToken.None);

                    // Assert
                    success.Should().BeTrue();
                    indexJsonOutput.Exists.Should().BeTrue();
                    settingsOutput.Exists.Should().BeTrue();
                    autoCompleteOutput.Exists.Should().BeTrue();
                    catalogOutput.Exists.Should().BeTrue();
                    searchOutput.Exists.Should().BeTrue();
                    packageIndexOutput.Exists.Should().BeTrue();
                    symbolsIndexOutput.Exists.Should().BeTrue();

                    log.GetMessages().Should().Contain("catalogpagesize : 1024");
                    log.GetMessages().Should().Contain("catalogenabled : true");
                    log.GetMessages().Should().Contain("symbolsfeedenabled : true");

                    rootJson.ToString().Should().Contain("catalog/index.json");
                    rootJson.ToString().Should().Contain("Catalog/3.0.0");
                    rootJson.ToString().Should().Contain("symbols/packages/index.json");
                }
        }
Exemplo n.º 6
0
        public async Task NuGetReader_DownloadPackageAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var globalFolder = new TestFolder())
                    using (var target = new TestFolder())
                        using (var cache = new LocalCache())
                        {
                            var outputRoot = Path.Combine(target.Root, "output");
                            var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                            var log         = new TestLogger();
                            var testPackage = new TestNupkg("packageA", "1.0.0");

                            var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                            var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                            await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig);

                            var zipFile = testPackage.Save(packagesFolder.Root);

                            var settings   = LocalSettings.Load(sleetConfigPath);
                            var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local");

                            var success = await InitCommand.RunAsync(settings, fileSystem, log);

                            // Act
                            // Run sleet
                            success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder.Root }, false, false, log);

                            // Create a repository abstraction for nuget
                            var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri);
                            var localSource     = GetSource(outputRoot, baseUri, nugetFileSystem);

                            var resource = await localSource.GetResourceAsync <DownloadResource>();

                            var cacheContext = new SourceCacheContext()
                            {
                                NoCache = true
                            };

                            var downloadContext = new PackageDownloadContext(cacheContext, globalFolder, directDownload: false);

                            var result = await resource.GetDownloadResourceResultAsync(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), downloadContext, globalFolder, log, CancellationToken.None);

                            // Assert
                            Assert.True(success, log.ToString());

                            Assert.Equal(DownloadResourceResultStatus.Available, result.Status);
                            Assert.True(result.PackageStream.Length > 0);
                            Assert.Equal(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), result.PackageReader.GetIdentity());
                        }
        }
Exemplo n.º 7
0
        public async Task VerifyUnSetUpdatesIndexJson()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var outputFolder = new TestFolder())
                        {
                            var log        = new TestLogger();
                            var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                            var settings   = new LocalSettings();

                            var context = new SleetContext()
                            {
                                Token          = CancellationToken.None,
                                LocalSettings  = settings,
                                Log            = log,
                                Source         = fileSystem,
                                SourceSettings = new FeedSettings()
                            };

                            var success = await InitCommand.RunAsync(settings, fileSystem, log);

                            success &= await FeedSettingsCommand.RunAsync(
                                settings,
                                fileSystem,
                                unsetAll : false,
                                getAll : false,
                                getSettings : Array.Empty <string>(),
                                unsetSettings : Array.Empty <string>(),
                                setSettings : new string[] { "externalsearch:https://example.org/search/query" },
                                log : log,
                                token : context.Token);

                            success &= await FeedSettingsCommand.RunAsync(
                                settings,
                                fileSystem,
                                unsetAll : false,
                                getAll : false,
                                getSettings : Array.Empty <string>(),
                                unsetSettings : new string[] { "externalsearch" },
                                setSettings : Array.Empty <string>(),
                                log : log,
                                token : context.Token);

                            success.Should().BeTrue();

                            var indexJsonPath = Path.Combine(target.RootDirectory.FullName, "index.json");
                            var entry         = GetSearchEntry(indexJsonPath);
                            var value         = entry["@id"].ToObject <string>();

                            value.Should().NotBe("https://example.org/search/query");
                        }
        }
Exemplo n.º 8
0
        public async Task GivenSettingsAddedVerifySingleGetReturnsJustOne()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var cache2 = new LocalCache())
                            using (var outputFolder = new TestFolder())
                            {
                                var log         = new TestLogger();
                                var fileSystem  = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                                var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));
                                var settings    = new LocalSettings();

                                var context = new SleetContext()
                                {
                                    Token          = CancellationToken.None,
                                    LocalSettings  = settings,
                                    Log            = log,
                                    Source         = fileSystem,
                                    SourceSettings = new FeedSettings()
                                };

                                var success = await InitCommand.RunAsync(settings, fileSystem, log);

                                success &= await FeedSettingsCommand.RunAsync(
                                    settings,
                                    fileSystem,
                                    unsetAll : false,
                                    getAll : false,
                                    getSettings : new string[] { },
                                    unsetSettings : new string[] { },
                                    setSettings : new string[] { "catalogenabled:false", "a:1" },
                                    log : log,
                                    token : context.Token);

                                success &= await FeedSettingsCommand.RunAsync(
                                    settings,
                                    fileSystem2,
                                    unsetAll : false,
                                    getAll : false,
                                    getSettings : new string[] { "a" },
                                    unsetSettings : new string[] { },
                                    setSettings : new string[] { },
                                    log : log,
                                    token : context.Token);

                                success.Should().BeTrue();
                                log.GetMessages().Should().NotContain("catalogenabled : false");
                                log.GetMessages().Should().Contain("a : 1");
                            }
        }
Exemplo n.º 9
0
        public void SubFeed_VerifySubFeedPath()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var root       = UriUtility.CreateUri(target.Root, "feedA");
                    var fileSystem = new PhysicalFileSystem(cache, root, root, feedSubPath: "feedA");

                    fileSystem.Root.Should().Be(UriUtility.EnsureTrailingSlash(root));
                    fileSystem.LocalRoot.Should().StartWith(Path.Combine(target.Root, "feedA"));

                    fileSystem.Get("index.json").EntityUri.Should().Be(UriUtility.GetPath(root, "index.json"));
                }
        }
Exemplo n.º 10
0
        public async Task BaseUri_VerifyBaseUriIsSetForAllFiles()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var outputRoot = Path.Combine(target.Root, "output");
                        var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                        var log      = new TestLogger();
                        var settings = new LocalSettings();

                        var testPackage = new TestPackageContext()
                        {
                            Nuspec = new TestNuspecContext()
                            {
                                Id      = "packageA",
                                Version = "1.0.0"
                            }
                        };

                        var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                        var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                        JsonUtility.SaveJson(new FileInfo(sleetConfigPath), sleetConfig);

                        var zipFile = testPackage.Create(packagesFolder.Root);

                        // Act
                        var exitCode = await Program.MainCore(new[] { "init", "-c", sleetConfigPath, "-s", "local" }, log);

                        exitCode += await Program.MainCore(new[] { "push", zipFile.FullName, "-c", sleetConfigPath, "-s", "local" }, log);

                        var files = Directory.GetFiles(outputRoot, "*.json", SearchOption.AllDirectories);

                        // Assert
                        Assert.True(0 == exitCode, log.ToString());

                        foreach (var file in files)
                        {
                            var fileJson = JsonUtility.LoadJson(new FileInfo(file));

                            foreach (var entityId in GetEntityIds(fileJson))
                            {
                                Assert.True(entityId.StartsWith(baseUri.AbsoluteUri), $"{entityId} in {file}");
                            }
                        }
                    }
        }
Exemplo n.º 11
0
        public async Task NuGetReader_MultiplePackagesOnRegistrationWithRemoveAsync()
        {
            // Arrange
            using (var sourceCacheContext = new SourceCacheContext())
                using (var packagesFolder = new TestFolder())
                    using (var target = new TestFolder())
                        using (var cache = new LocalCache())
                        {
                            var outputRoot = Path.Combine(target.Root, "output");
                            var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                            var log = new TestLogger();

                            var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                            var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                            await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig);

                            var settings   = LocalSettings.Load(sleetConfigPath);
                            var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local");

                            var success = await InitCommand.RunAsync(settings, fileSystem, log);

                            // push 100 packages
                            for (var i = 0; i < 100; i++)
                            {
                                var testPackage = new TestNupkg("packageA", $"1.0.0-alpha.{i}");
                                var zipFile     = testPackage.Save(packagesFolder.Root);
                            }

                            success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder.Root }, false, false, log);

                            success &= await DeleteCommand.RunAsync(settings, fileSystem, "packageA", "1.0.0-alpha.5", string.Empty, false, log);

                            success &= await ValidateCommand.RunAsync(settings, fileSystem, log);

                            // Act
                            // Create a repository abstraction for nuget
                            var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri);
                            var localSource     = GetSource(outputRoot, baseUri, nugetFileSystem);

                            var resource = await localSource.GetResourceAsync <PackageMetadataResource>();

                            var packages = (await resource.GetMetadataAsync("packageA", true, true, sourceCacheContext, log, CancellationToken.None)).ToList();

                            // Assert
                            Assert.True(success, log.ToString());
                            Assert.Equal(99, packages.Count);
                        }
        }
Exemplo n.º 12
0
        public async Task NuGetReader_AutoCompleteAsync()
        {
            // Arrange
            using (var sourceCacheContext = new SourceCacheContext())
                using (var packagesFolder = new TestFolder())
                    using (var target = new TestFolder())
                        using (var cache = new LocalCache())
                        {
                            var outputRoot = Path.Combine(target.Root, "output");
                            var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                            var log         = new TestLogger();
                            var testPackage = new TestNupkg("packageA", "1.0.0");

                            var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                            var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                            await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig);

                            var zipFile = testPackage.Save(packagesFolder.Root);

                            var settings   = LocalSettings.Load(sleetConfigPath);
                            var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local");

                            var success = await InitCommand.RunAsync(settings, fileSystem, log);

                            fileSystem.Reset();

                            // Act
                            // Run sleet
                            success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder.Root }, false, false, log);

                            // Create a repository abstraction for nuget
                            var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri);
                            var localSource     = GetSource(outputRoot, baseUri, nugetFileSystem);

                            var resource = await localSource.GetResourceAsync <AutoCompleteResource>();

                            var ids = await resource.IdStartsWith("p", true, log, CancellationToken.None);

                            var versions = await resource.VersionStartsWith("packageA", "1", true, sourceCacheContext, log, CancellationToken.None);

                            // Assert
                            Assert.True(success, log.ToString());

                            Assert.Equal("packageA", ids.Single());
                            Assert.Equal("1.0.0", versions.Single().ToFullVersionString());
                        }
        }
Exemplo n.º 13
0
        public async Task GivenThatTheFeedHasMissingPackagesVerifyRecreateSucceedsWithForce()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var outputFolder = new TestFolder())
                        using (var cache = new LocalCache())
                            using (var cache2 = new LocalCache())
                                using (var cache3 = new LocalCache())
                                {
                                    var log      = new TestLogger();
                                    var settings = new LocalSettings();

                                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                                    await InitCommand.RunAsync(settings, fileSystem, log);

                                    var packageA = new TestNupkg("a", "1.0");
                                    var packageB = new TestNupkg("b", "2.0.0-beta+blah");
                                    packageA.Save(packagesFolder.Root);
                                    packageB.Save(packagesFolder.Root);

                                    await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log);

                                    var root = new DirectoryInfo(target);
                                    foreach (var file in root.GetFiles("a.1.0.0*", SearchOption.AllDirectories))
                                    {
                                        // Corrupt the feed
                                        file.Delete();
                                    }

                                    // Recreate
                                    var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root));

                                    var success = await RecreateCommand.RunAsync(settings, fileSystem2, outputFolder, force : true, log : log);

                                    success.Should().BeTrue();

                                    var fileSystem3 = new PhysicalFileSystem(cache3, UriUtility.CreateUri(target.Root));

                                    var finalPackages = (await fileSystem3.GetFiles(log, CancellationToken.None))
                                                        .Select(e => Path.GetFileName(e.EntityUri.LocalPath))
                                                        .Where(e => e.EndsWith(".nupkg"))
                                                        .OrderBy(e => e, StringComparer.OrdinalIgnoreCase);

                                    Directory.Exists(outputFolder).Should().BeFalse();

                                    log.GetMessages().Should().Contain("Feed recreation complete.");
                                }
        }
Exemplo n.º 14
0
        public async Task VerifyHasBucketWithMultipleLevelsReturnsFalse()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                    using (var extCache = new LocalCache())
                    {
                        var log  = new TestLogger();
                        var root = Path.Combine(target.RootDirectory.FullName, "testParent2/testParent1/testFeed");

                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(root));
                        var exists     = await fileSystem.HasBucket(log, CancellationToken.None);

                        exists.Should().Be(false);
                    }
        }
Exemplo n.º 15
0
        public void Feed_LocalTypeSupportsRelativePath(string configPath, string outputPath, string expected)
        {
            using (var cache = new LocalCache())
            {
                var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputPath, baseUri.AbsoluteUri);

                var settings   = LocalSettings.Load(sleetConfig, configPath);
                var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "local") as PhysicalFileSystem;

                Assert.NotNull(fileSystem);
                Assert.Equal(expected, fileSystem.LocalRoot);
            }
        }
Exemplo n.º 16
0
        public void GivenThatTheFeedIsNotInitializedVerifyCommandFails()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var outputFolder = new TestFolder())
                        {
                            var log        = new TestLogger();
                            var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                            var settings   = new LocalSettings();

                            Func <Task> action = async() => await DownloadCommand.RunAsync(settings, fileSystem, outputFolder, false, log);

                            action.ShouldThrow <InvalidOperationException>("the feed is not initialized");
                        }
        }
Exemplo n.º 17
0
        public void GivenThatIWantToDestroyAFeedVerifyAnEmptyFeedThrows()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                        using (var outputFolder = new TestFolder())
                        {
                            var log        = new TestLogger();
                            var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                            var settings   = new LocalSettings();

                            Func <Task> task = async() => await DestroyCommand.RunAsync(settings, fileSystem, log);

                            task.ShouldThrow <InvalidOperationException>();
                        }
        }
Exemplo n.º 18
0
        public async Task UpgradeUtility_Verify210FeedsAreNotCompatibleAsync()
        {
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        // Init
                        await InitCommand.InitAsync(context);

                        // Change index.json
                        var indexJsonPath = Path.Combine(target.Root, "index.json");
                        var json          = JObject.Parse(File.ReadAllText(indexJsonPath));
                        json["sleet:version"] = "2.1.1";
                        File.WriteAllText(indexJsonPath, json.ToString());

                        Exception ex = null;
                        try
                        {
                            var fileSystem2 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                            await UpgradeUtility.EnsureCompatibility(fileSystem2, log, CancellationToken.None);
                        }
                        catch (Exception current)
                        {
                            ex = current;
                        }

                        ex.Should().NotBeNull();
                        ex.Message.Should().Contain("Sleet recreate");
                    }
        }
Exemplo n.º 19
0
        public async Task NuGetReader_MultiplePackagesOnRegistrationWithRemove()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var outputRoot = Path.Combine(target.Root, "output");
                        var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                        var log = new TestLogger();

                        var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                        var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                        JsonUtility.SaveJson(new FileInfo(sleetConfigPath), sleetConfig);

                        var exitCode = await Program.MainCore(new[] { "init", "-c", sleetConfigPath, "-s", "local" }, log);

                        // push 100 packages
                        for (int i = 0; i < 100; i++)
                        {
                            var testPackage = new TestPackageContext("packageA", $"1.0.0-alpha.{i}");
                            var zipFile     = testPackage.Create(packagesFolder.Root);
                        }

                        exitCode += await Program.MainCore(new[] { "push", packagesFolder.Root, "-c", sleetConfigPath, "-s", "local" }, log);

                        exitCode += await Program.MainCore(new[] { "delete", "--id", "packageA", "--version", "1.0.0-alpha.5", "-c", sleetConfigPath, "-s", "local" }, log);

                        exitCode += await Program.MainCore(new[] { "validate", "-c", sleetConfigPath, "-s", "local" }, log);

                        // Act
                        // Create a repository abstraction for nuget
                        var fileSystem  = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri);
                        var localSource = GetSource(outputRoot, baseUri, fileSystem);

                        var resource = await localSource.GetResourceAsync <PackageMetadataResource>();

                        var packages = (await resource.GetMetadataAsync("packageA", true, true, log, CancellationToken.None)).ToList();

                        // Assert
                        Assert.True(0 == exitCode, log.ToString());
                        Assert.Equal(99, packages.Count);
                    }
        }
Exemplo n.º 20
0
        public async Task BaseUri_VerifyBaseUriIsSetForAllFilesAsync()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var outputRoot = Path.Combine(target.Root, "output");
                        var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                        var log = new TestLogger();

                        var testPackage = new TestNupkg("packageA", "1.0.0");

                        var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                        var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                        await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig);

                        var zipFile = testPackage.Save(packagesFolder.Root);

                        var settings   = LocalSettings.Load(sleetConfigPath);
                        var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "local");

                        // Act
                        var initSuccess = await InitCommand.RunAsync(settings, fileSystem, log);

                        var pushSuccess = await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, false, false, log);

                        var files = Directory.GetFiles(outputRoot, "*.json", SearchOption.AllDirectories);

                        // Assert
                        Assert.True(initSuccess, log.ToString());
                        Assert.True(pushSuccess, log.ToString());

                        foreach (var file in files)
                        {
                            var fileJson = await JsonUtility.LoadJsonAsync(new FileInfo(file));

                            foreach (var entityId in GetEntityIds(fileJson))
                            {
                                Assert.True(entityId.StartsWith(baseUri.AbsoluteUri), $"{entityId} in {file}");
                            }
                        }
                    }
        }
Exemplo n.º 21
0
        public async Task VerifyValidate()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                    using (var extCache = new LocalCache())
                    {
                        var log  = new TestLogger();
                        var root = Path.Combine(target.RootDirectory.FullName, "testParent2/testParent1/testFeed");

                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(root));

                        (await fileSystem.HasBucket(log, CancellationToken.None)).Should().BeFalse();
                        await fileSystem.CreateBucket(log, CancellationToken.None);

                        (await fileSystem.HasBucket(log, CancellationToken.None)).Should().BeTrue();
                    }
        }
Exemplo n.º 22
0
        public async Task Feed_LocalTypeSupportsRelativePath(string configPath, string outputPath, string expected)
        {
            var expectedFull = expected.Replace("{workingDir}", Directory.GetCurrentDirectory());

            using (var cache = new LocalCache())
            {
                var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputPath, baseUri.AbsoluteUri);

                var settings   = LocalSettings.Load(sleetConfig, configPath);
                var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local") as PhysicalFileSystem;

                Assert.NotNull(fileSystem);
                Assert.Equal(expectedFull, fileSystem.LocalRoot);
            }
        }
Exemplo n.º 23
0
        public async Task NuGetReader_FindPackageByIdResource()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var outputRoot = Path.Combine(target.Root, "output");
                        var baseUri    = UriUtility.CreateUri("https://localhost:8080/testFeed/");

                        var log         = new TestLogger();
                        var testPackage = new TestPackageContext("packageA", "1.0.0");

                        var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri);

                        var sleetConfigPath = Path.Combine(target.Root, "sleet.config");
                        JsonUtility.SaveJson(new FileInfo(sleetConfigPath), sleetConfig);

                        var zipFile = testPackage.Create(packagesFolder.Root);

                        // Act
                        // Run sleet
                        var exitCode = await Program.MainCore(new[] { "init", "-c", sleetConfigPath, "-s", "local" }, log);

                        exitCode += await Program.MainCore(new[] { "push", zipFile.FullName, "-c", sleetConfigPath, "-s", "local" }, log);

                        // Create a repository abstraction for nuget
                        var fileSystem  = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri);
                        var localSource = GetSource(outputRoot, baseUri, fileSystem);

                        var resource = await localSource.GetResourceAsync <FindPackageByIdResource>();

                        resource.Logger       = log;
                        resource.CacheContext = new SourceCacheContext()
                        {
                            NoCache = true
                        };

                        var versions = await resource.GetAllVersionsAsync("packageA", CancellationToken.None);

                        // Assert
                        Assert.True(0 == exitCode, log.ToString());
                        Assert.Equal("1.0.0", versions.Single().ToFullVersionString());
                    }
        }
Exemplo n.º 24
0
        public async Task GivenAFileWriteVerifyGetAfter()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var log        = new TestLogger();
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                    var a = fileSystem.Get("a.txt");
                    await a.Write(new JObject(), log, CancellationToken.None);

                    var json = await a.GetJson(log, CancellationToken.None);

                    a.HasChanges.Should().BeTrue();
                    cache.Root.GetFiles().Length.Should().Be(1);
                    json.ToString().Should().Be((new JObject()).ToString());
                }
        }
Exemplo n.º 25
0
        public async Task PushCommand_GivenAEmptyFolderVerifyAutoInit()
        {
            // Arrange
            using (var packagesFolder = new TestFolder())
                using (var target = new TestFolder())
                    using (var cache = new LocalCache())
                    {
                        var root = Path.Combine(target.Root, "a/b/feed");
                        Directory.CreateDirectory(root);

                        var log        = new TestLogger();
                        var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(root));
                        var settings   = new LocalSettings();

                        var context = new SleetContext()
                        {
                            Token          = CancellationToken.None,
                            LocalSettings  = settings,
                            Log            = log,
                            Source         = fileSystem,
                            SourceSettings = new FeedSettings()
                            {
                                CatalogEnabled = true
                            }
                        };

                        var testPackage     = new TestNupkg("packageA", "1.0.0");
                        var packageIdentity = new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version));

                        var zipFile = testPackage.Save(packagesFolder.Root);

                        // Act
                        await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log);

                        var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log);

                        // read outputs
                        var packageIndex  = new PackageIndex(context);
                        var indexPackages = await packageIndex.GetPackagesAsync();

                        // Assert
                        Assert.Equal(1, indexPackages.Count);
                    }
        }
Exemplo n.º 26
0
        public async Task GivenAFileVerifyExistsDoesNotDownload()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var log        = new TestLogger();
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                    File.WriteAllText(Path.Combine(target, "a.txt"), ".");

                    var a = fileSystem.Get("a.txt");

                    var exists = await a.Exists(log, CancellationToken.None);

                    exists.Should().BeTrue();
                    a.HasChanges.Should().BeFalse();
                    cache.Root.GetFiles().Should().BeEmpty();
                }
        }
Exemplo n.º 27
0
        public void GivenAFileVerifyGetPathGivesTheSameFile()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var log        = new TestLogger();
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                    var a = fileSystem.Get("a.txt");

                    var test1 = fileSystem.Get("a.txt");
                    var test2 = fileSystem.Get(new Uri(a.EntityUri.AbsoluteUri));
                    var test3 = fileSystem.Get("/a.txt");

                    ReferenceEquals(a, test1).Should().BeTrue();
                    ReferenceEquals(a, test2).Should().BeTrue();
                    ReferenceEquals(a, test3).Should().BeTrue();
                }
        }
Exemplo n.º 28
0
        public void GivenAnHttpPathVerifyThrows()
        {
            using (var cache = new LocalCache())
            {
                Exception ex = null;

                try
                {
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri("https://example.com/feed/"));
                }
                catch (Exception e)
                {
                    ex = e;
                }

                ex.Should().NotBeNull();
                ex.Message.Should().Be("Local feed path cannot be an http URI, use baseURI instead.");
            }
        }
Exemplo n.º 29
0
        public async Task GivenThatICreateAndDeleteAFileInTheSameSessionVerifyItIsRemoved()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var log        = new TestLogger();
                    var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));

                    var a = fileSystem.Get("a.txt");

                    await a.Write(new JObject(), log, CancellationToken.None);

                    a.Delete(log, CancellationToken.None);

                    await fileSystem.Commit(log, CancellationToken.None);

                    File.Exists(a.RootPath.LocalPath).Should().BeFalse("the file was deleted");
                }
        }
Exemplo n.º 30
0
        public async Task FileSystem_VerifyFileSystemResetOnLock()
        {
            using (var target = new TestFolder())
                using (var cache = new LocalCache())
                {
                    var log         = new TestLogger();
                    var fileSystem1 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root));
                    var settings    = new LocalSettings();
                    var lockMessage = Guid.NewGuid().ToString();

                    await InitCommand.RunAsync(settings, fileSystem1, log);

                    // Verify that files work normally
                    var testFile = fileSystem1.Get("test.json");
                    await testFile.GetJsonOrNull(log, CancellationToken.None);

                    var testFile2 = fileSystem1.Get("test2.json");
                    fileSystem1.Files.Count.Should().BeGreaterThan(1);

                    // Lock the feed to reset it
                    var lockObj1 = await SourceUtility.VerifyInitAndLock(settings, fileSystem1, lockMessage, log, CancellationToken.None);

                    lockObj1.IsLocked.Should().BeTrue();

                    // 1 file should be found since it loads the index
                    fileSystem1.Files.Count.Should().Be(1);
                    InvalidOperationException failureEx = null;

                    try
                    {
                        // Verify the old file no longer works
                        await testFile.GetJsonOrNull(log, CancellationToken.None);

                        await testFile2.GetJsonOrNull(log, CancellationToken.None);
                    }
                    catch (InvalidOperationException ex)
                    {
                        failureEx = ex;
                    }

                    failureEx.Should().NotBeNull();
                }
        }