public async Task UpgradeUtility_VerifyMatchingVersionOfCapabilityWorksAsync() { 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:capabilities"] = "schema:1.0.0"; File.WriteAllText(indexJsonPath, json.ToString()); var fileSystem2 = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); await UpgradeUtility.EnsureCompatibility(fileSystem2, log, CancellationToken.None); } }
public async Task Symbols_VerifyFilesExistAfterPush() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var testPackage = new TestNupkg("packageA", "1.0.0"); testPackage.Files.Clear(); testPackage.AddFile("lib/net45/SymbolsTestA.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestA.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestB.dll", TestUtility.GetResource("SymbolsTestBdll").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestB.pdb", TestUtility.GetResource("SymbolsTestBpdb").GetBytes()); var zipFile = testPackage.Save(testContext.Packages); // run commands await InitCommand.InitAsync(context); // add package await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); // validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); validateOutput.Should().BeTrue(); } }
public async Task SubFeed_InitTwoFeedsDestroyOneVerifyFirst() { using (var target = new TestFolder()) using (var cache = new LocalCache()) using (var cache2 = new LocalCache()) { var log = new TestLogger(); var settings = new LocalSettings(); var feedSettings = new FeedSettings(); var rootFeedA = UriUtility.CreateUri(target.Root, "feedA"); var rootFeedB = UriUtility.CreateUri(target.Root, "feedB"); var fileSystem = new PhysicalFileSystem(cache, rootFeedA, rootFeedA, feedSubPath: "feedA"); var fileSystem2 = new PhysicalFileSystem(cache2, rootFeedB, rootFeedB, feedSubPath: "feedB"); // Init feeds var success = await InitCommand.InitAsync(settings, fileSystem, feedSettings, log, CancellationToken.None); success &= await InitCommand.InitAsync(settings, fileSystem2, feedSettings, log, CancellationToken.None); // Destroy feed 2 success &= await DestroyCommand.Destroy(settings, fileSystem2, log, CancellationToken.None); // Validate feed 1 success &= await ValidateCommand.Validate(settings, fileSystem, log, CancellationToken.None); success.Should().BeTrue(); target.RootDirectory.GetFiles().Should().BeEmpty(); target.RootDirectory.GetDirectories().Select(e => e.Name).ShouldBeEquivalentTo(new[] { "feedA" }); } }
public async Task BadgeFile_VerifyBadgesUpdatedAfterDeleteAll() { // 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("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); // Remove await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "a", "2.0.0", "test", true, context.Log); // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); validateOutput.Should().BeTrue(); // read output var stablePath = Path.Combine(target.Root, "badges/v/a.svg"); var prePath = Path.Combine(target.Root, "badges/vpre/a.svg"); File.Exists(stablePath).Should().BeFalse(); File.Exists(prePath).Should().BeFalse(); var stablePathJson = Path.Combine(target.Root, "badges/v/a.json"); var prePathJson = Path.Combine(target.Root, "badges/vpre/a.json"); File.Exists(stablePathJson).Should().BeFalse(); File.Exists(prePathJson).Should().BeFalse(); } }
public static async Task CreateCatalogAsync(string root, string feedRoot, string nupkgFolder, Uri baseUri, int catalogPageSize, ILogger log) { using (var cache = new LocalCache()) { var sleetConfig = CreateSleetConfig(root, feedRoot, baseUri); var settings = LocalSettings.Load(sleetConfig); var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "feed"); var feedSettings = await FeedSettingsUtility.GetSettingsOrDefault(fileSystem, log, CancellationToken.None); feedSettings.CatalogEnabled = true; feedSettings.SymbolsEnabled = false; feedSettings.CatalogPageSize = catalogPageSize; var success = await InitCommand.InitAsync(settings, fileSystem, feedSettings, log, CancellationToken.None); if (success != true) { throw new InvalidOperationException("Catalog init failed"); } if (Directory.GetFiles(nupkgFolder).Any()) { success = await PushCommand.PushPackages(settings, fileSystem, new List <string>() { nupkgFolder }, false, false, log, CancellationToken.None); if (success != true) { throw new InvalidOperationException("Push failed"); } } } }
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()); } }
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"); } }
public async Task RetentionSettingsCommand_DisableRetention() { // 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, SymbolsEnabled = true } }; await InitCommand.InitAsync(context); // Enable retention var success = await RetentionSettingsCommand.RunAsync(context.LocalSettings, context.Source, 10, 5, 2, false, log); // Disable retention success &= await RetentionSettingsCommand.RunAsync(context.LocalSettings, context.Source, -1, -1, true, log); var updatedSettings = await FeedSettingsUtility.GetSettingsOrDefault(context.Source, log, context.Token); success.Should().BeTrue(); updatedSettings.RetentionMaxStableVersions.Should().BeNull(); updatedSettings.RetentionMaxPrereleaseVersions.Should().BeNull(); updatedSettings.RetentionGroupByFirstPrereleaseLabelCount.Should().BeNull(); } }
public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds() { // 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 } }; context.SourceSettings.CatalogEnabled = false; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false) { Zip = zip, Package = new PackageArchiveReader(zip) }; var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); 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 catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEquivalentTo(new[] { input.Identity }); indexPackages.Should().BeEquivalentTo(new[] { input.Identity }); searchPackages.Should().BeEquivalentTo(new[] { input.Identity }); autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id }); catalogLatest.Should().BeNull(); catalogEntry["version"].ToString().Should().Be("1.0.0"); catalogEntry["sleet:operation"].ToString().Should().Be("add"); } } }
public async Task Feed_VerifyBaseUriIsAppliedToLocal(string baseUriString) { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystemRoot = UriUtility.CreateUri(target.Root); var baseUri = new Uri(baseUriString); var fileSystem = new PhysicalFileSystem(cache, fileSystemRoot, baseUri); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false) { Zip = zip, Package = new PackageArchiveReader(zip) }; var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); 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 catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(1, indexPackages.Count); Assert.Equal(1, searchPackages.Count); Assert.Equal(1, autoCompletePackages.Count); // Walk json to check for bad urls await TestUtility.WalkJsonAsync(target.Root, (file, json, toCheck) => { // Check only URLs found if (toCheck.IndexOf("://") > -1) { var cleanUriSchema = toCheck.Replace(":///", string.Empty).Replace("://", string.Empty); var doubleSlash = cleanUriSchema.IndexOf("//") > -1; Assert.False(doubleSlash, toCheck); } }); } } }
public async Task RetentionPruneCommand_PrunesOnPushWithMultiplePushes() { // Arrange using (var packagesFolder = new TestFolder()) using (var packagesFolder2 = 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, SymbolsEnabled = true, RetentionMaxStableVersions = 2, RetentionMaxPrereleaseVersions = 1 } }; // Initial packages var identities = new List <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0")), }; await InitCommand.InitAsync(context); // Push packages 1 at a time foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); } // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(6); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); } }
public async Task PushCommand_GivenADifferentNuspecCasingVerifyPush() { // 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 testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var tempZip = new ZipArchive(zipFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None), ZipArchiveMode.Update)) { var nuspec = tempZip.Entries.Single(e => e.FullName == "packageA.nuspec"); using (var ms = new MemoryStream()) { using (var nuspecStream = nuspec.Open()) { nuspecStream.CopyTo(ms); } ms.Position = 0; nuspec.Delete(); var newEntry = tempZip.CreateEntry("PacKAGEa.NuSpec"); ms.CopyTo(newEntry.Open()); } } using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); // Act // run commands await InitCommand.InitAsync(context); 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 catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, indexPackages.Count); } } }
public async Task AddRemove_AddTwoPackagesOfUniqueIds() { // 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("packageB", "1.0.0"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); using (var zip1 = new ZipArchive(File.OpenRead(zipFile1.FullName), ZipArchiveMode.Read, false)) using (var zip2 = new ZipArchive(File.OpenRead(zipFile2.FullName), ZipArchiveMode.Read, false)) { var input1 = PackageInput.Create(zipFile1.FullName); var input2 = PackageInput.Create(zipFile2.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(2, catalogEntries.Count); Assert.Equal(2, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(2, indexPackages.Count); Assert.Equal(2, searchPackages.Count); Assert.Equal(2, autoCompletePackages.Count); } } }
public async Task AddRemove_AddManyPackagesThenRemoveSome() { // 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, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>(); var ids = new[] { "a", "b", "c", "d" }; foreach (var id in ids) { for (var i = 0; i < 50; i++) { var testPackage = new TestNupkg(id, $"{i}.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); identities.Add(new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version))); } } var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); // Act // run delete command await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "b", null, "removing", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogPackages = await catalog.GetPackagesAsync(); var regPackages = new HashSet <PackageIdentity>(); foreach (var id in ids) { regPackages.UnionWith(await registration.GetPackagesByIdAsync(id)); } var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(identities.Count + 50, catalogEntries.Count); Assert.Equal(identities.Count - 50, catalogExistingEntries.Count); regPackages.Count.Should().Be(identities.Count - 50); Assert.Equal(identities.Count - 50, indexPackages.Count); Assert.Equal(identities.Count - 50, searchPackages.Count); Assert.Equal(ids.Length - 1, autoCompletePackages.Count); } }
public async Task GivenThatIRemoveAllPackagesWithTheCatalogDisabledVerifyItSucceeds() { // 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 } }; context.SourceSettings.CatalogEnabled = false; var testPackage1 = new TestNupkg("packageA", "1.0.1"); var testPackage2 = new TestNupkg("packageA", "1.0.2"); var testPackage3 = new TestNupkg("packageA", "1.0.3"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var zipFile3 = testPackage3.Save(packagesFolder.Root); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile3.FullName }, false, false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.2", "", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEmpty("all packages were removed"); indexPackages.Should().BeEmpty("all packages were removed"); searchPackages.Should().BeEmpty("all packages were removed"); autoCompletePackages.Should().BeEmpty("all packages were removed"); } }
public async Task AddRemove_AddAndRemovePackageAsync() { // 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 testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = new PackageInput(zipFile.FullName, new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), false) { Zip = zip, Package = new PackageArchiveReader(zip) }; var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.0", string.Empty, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(2, catalogEntries.Count); Assert.Equal(0, catalogExistingEntries.Count); Assert.Equal(0, regPackages.Count); Assert.Equal(0, indexPackages.Count); Assert.Equal(0, searchPackages.Count); Assert.Equal(0, autoCompletePackages.Count); Assert.Equal("packageA", catalogLatest.Id); Assert.Equal("1.0.0", catalogLatest.Version.ToIdentityString()); Assert.Equal(SleetOperation.Remove, catalogLatest.Operation); } } }
public async Task RetentionPruneCommand_NoopsWhenNoPackagesNeedToBeRemoved() { // 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, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("a", NuGetVersion.Parse("4.0.0")), new PackageIdentity("a", NuGetVersion.Parse("5.0.0")), }; foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); } await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); var pruneContext = new RetentionPruneCommandContext() { StableVersionMax = 10, PrereleaseVersionMax = 10 }; // Run prune await RetentionPruneCommand.PrunePackages(context, pruneContext); // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(5); } }