From 5ad0a529c1be76602bcf6e4842b7f1c37187db32 Mon Sep 17 00:00:00 2001 From: Vincent Wilms Date: Fri, 27 Sep 2024 10:18:04 +0200 Subject: [PATCH] Prepare release --- CHANGELOG.md | 4 ++ src/Nexus.Sources.Federation/Federation.cs | 3 ++ .../FederationTests.cs | 52 +++++++++++++++++++ version.json | 2 +- 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd7c3fc..77181e9 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## v2.0.0-beta.25 - 2024-09-27 + +- Fix nested catalogs not being loaded properly. + ## v2.0.0-beta.24 - 2024-03-15 - Follow Nexus changes. diff --git a/src/Nexus.Sources.Federation/Federation.cs b/src/Nexus.Sources.Federation/Federation.cs index 9fdf5cd..3737971 100644 --- a/src/Nexus.Sources.Federation/Federation.cs +++ b/src/Nexus.Sources.Federation/Federation.cs @@ -74,6 +74,9 @@ public async Task GetCatalogRegistrationsAsync(string pat if (path == "/") path = _mountPoint; + else + path = path.TrimEnd('/'); + var catalogInfos = await _nexusClient.Catalogs.GetChildCatalogInfosAsync(ToSourcePathPrefixedCatalogId(path), cancellationToken); return catalogInfos diff --git a/tests/Nexus.Sources.Federation.Tests/FederationTests.cs b/tests/Nexus.Sources.Federation.Tests/FederationTests.cs index ce7d9bb..113d19b 100644 --- a/tests/Nexus.Sources.Federation.Tests/FederationTests.cs +++ b/tests/Nexus.Sources.Federation.Tests/FederationTests.cs @@ -35,6 +35,7 @@ public async Task ProvidesCatalogRegistrations(string? sourcePath, string? mount .ReturnsAsync((string catalogId, CancellationToken cancellationToken) => { Assert.True(catalogId.StartsWith('/')); + Assert.True(catalogId == "/" || !catalogId.EndsWith('/')); var childCatalogId = catalogId == "/" ? catalogId + "TEST_CATALOG" @@ -72,4 +73,55 @@ public async Task ProvidesCatalogRegistrations(string? sourcePath, string? mount // assert Assert.Equal(expectedCatalogId, catalogRegistrations.First().Path); } + + [Fact] + public async Task ProvidesNestedCatalogRegistrations() + { + var expectedCatalogId = "/mnt/name"; + var searchPath = "/mnt/"; /* with trailing slash because Nexus does the same! */ + + // arrange + var catalogsClient = Mock.Of(); + + Mock.Get(catalogsClient) + .Setup(catalog => catalog.GetChildCatalogInfosAsync( + It.IsAny(), + It.IsAny() + )) + .ReturnsAsync((string catalogId, CancellationToken cancellationToken) => + { + Assert.True(catalogId.StartsWith('/')); + Assert.True(!catalogId.EndsWith('/')); + + var childCatalogId = expectedCatalogId; + var catalog = new CatalogInfo(childCatalogId, default, default, default, default, default, default, default, default, default, default, default!, default, default); + + return new List() { catalog }; + }); + + var nexusClient = Mock.Of(); + + Mock.Get(nexusClient) + .SetupGet(client => client.Catalogs) + .Returns(catalogsClient); + + var dataSource = new Federation() { CreateNexusClient = _ => nexusClient } as IDataSource; + + var context = new DataSourceContext( + ResourceLocator: new Uri("https://example.com"), + SystemConfiguration: default!, + SourceConfiguration: new Dictionary() + { + ["access-token"] = JsonSerializer.SerializeToElement("") + }, + RequestConfiguration: default!); + + await dataSource.SetContextAsync(context, NullLogger.Instance, CancellationToken.None); + + // act + var catalogRegistrations = await dataSource.GetCatalogRegistrationsAsync(searchPath, CancellationToken.None); + + // assert + Assert.Equal(expectedCatalogId, catalogRegistrations.First().Path); + } } \ No newline at end of file diff --git a/version.json b/version.json index d5c1679..889ce0c 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "version": "2.0.0", - "suffix": "beta.24" + "suffix": "beta.25" } \ No newline at end of file