Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task ListNamespacesAsync_ShouldSendParentPageTokenAndPageSize()
await this.Catalog().ListNamespacesAsync(new ListNamespacesOptions
{
Parent = IcebergNamespace.Of("sales", "europe"),
PageToken = "a/b",
NextPageToken = "a/b",
PageSize = 10,
});
this.server.LogEntries.Should().ContainSingle().Which.RequestMessage!.Url
Expand All @@ -91,7 +91,7 @@ public async Task ListNamespacesAsync_ShouldMapNamespacesAndNextPageToken()
var page = await this.Catalog().ListNamespacesAsync();
using (new AssertionScope())
{
page.Namespaces.Should().Equal(IcebergNamespace.Of("sales"), IcebergNamespace.Of("ops"));
page.Items.Should().Equal(IcebergNamespace.Of("sales"), IcebergNamespace.Of("ops"));
page.NextPageToken.Should().Be("abc");
}
}
Expand All @@ -100,7 +100,7 @@ public async Task ListNamespacesAsync_ShouldMapNamespacesAndNextPageToken()
public async Task ListNamespacesAsync_ShouldMapMultiLevelNamespaces()
{
this.Respond(200, "{\"namespaces\":[[\"sales\",\"europe\"]]}");
(await this.Catalog().ListNamespacesAsync()).Namespaces.Should().Equal(IcebergNamespace.Of("sales", "europe"));
(await this.Catalog().ListNamespacesAsync()).Items.Should().Equal(IcebergNamespace.Of("sales", "europe"));
}

[TestMethod]
Expand All @@ -117,7 +117,7 @@ public async Task ListNamespacesAsync_ShouldReturnEmptyPage_GivenNoNamespacesInR
var page = await this.Catalog().ListNamespacesAsync();
using (new AssertionScope())
{
page.Namespaces.Should().BeEmpty();
page.Items.Should().BeEmpty();
page.NextPageToken.Should().BeNull();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task ListTablesAsync_ShouldSendNoPagingParameter_GivenNoOptions()
public async Task ListTablesAsync_ShouldSendPageSizeAndToken_GivenOptions()
{
this.Respond(TablesPath, 200, Listed);
await this.Catalog().ListTablesAsync(Sales, new ListTablesOptions { PageSize = 2, PageToken = "next/page token" });
await this.Catalog().ListTablesAsync(Sales, new ListTablesOptions { PageSize = 2, NextPageToken = "next/page token" });
var query = this.server.LogEntries.Should().ContainSingle().Which.RequestMessage!.Query!;
using (new AssertionScope())
{
Expand All @@ -97,15 +97,15 @@ public async Task ListTablesAsync_ShouldJoinNamespaceLevelsWithTheUnitSeparator(
public async Task ListTablesAsync_ShouldReturnTheListedTablesInOrder()
{
this.Respond(TablesPath, 200, Listed);
(await this.Catalog().ListTablesAsync(Sales)).Tables
(await this.Catalog().ListTablesAsync(Sales)).Items
.Should().Equal(Sales.Table("events"), Sales.Table("orders"));
}

[TestMethod]
public async Task ListTablesAsync_ShouldReturnTheNamespaceTheServiceSent()
{
this.Respond(TablesPath, 200, "{\"identifiers\":[{\"namespace\":[\"sales\",\"europe\"],\"name\":\"events\"}]}");
(await this.Catalog().ListTablesAsync(Sales)).Tables
(await this.Catalog().ListTablesAsync(Sales)).Items
.Should().ContainSingle().Which.Should().Be(IcebergNamespace.Of("sales", "europe").Table("events"));
}

Expand All @@ -115,15 +115,15 @@ public async Task ListTablesAsync_ShouldReturnTheNamespaceTheServiceSent()
public async Task ListTablesAsync_ShouldReturnTheListedNamespace_GivenIdentifierWithoutNamespace(string body)
{
this.Respond(TablesPath, 200, body);
(await this.Catalog().ListTablesAsync(Sales)).Tables
(await this.Catalog().ListTablesAsync(Sales)).Items
.Should().ContainSingle().Which.Should().Be(Sales.Table("events"));
}

[TestMethod]
public async Task ListTablesAsync_ShouldReturnNoTable_GivenResponseOmitsIdentifiers()
{
this.Respond(TablesPath, 200, "{}");
(await this.Catalog().ListTablesAsync(Sales)).Tables.Should().BeEmpty();
(await this.Catalog().ListTablesAsync(Sales)).Items.Should().BeEmpty();
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Storage.Tests.AnalyticsBuckets.Iceberg.ListTables;

/// <summary>
/// Unit tests for the checks made before the wire when listing the tables of a namespace, and for the defaults of its
/// options and page.
/// options.
/// </summary>
[TestClass]
[TestCategory("Unit")]
Expand All @@ -38,11 +38,7 @@ public void ListTablesOptions_ShouldSendNothing_GivenNoneSet()
using (new AssertionScope())
{
options.PageSize.Should().BeNull("the service owns the default page size");
options.PageToken.Should().BeNull("the first page needs no token");
options.NextPageToken.Should().BeNull("the first page needs no token");
}
}

[TestMethod]
public void IcebergTablePage_ShouldHaveNoTable_GivenNoneSet() =>
new IcebergTablePage().Tables.Should().BeEmpty();
}
17 changes: 17 additions & 0 deletions packages/Storage/Storage.Tests/Common/PageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Supabase.Storage.Common;

namespace Storage.Tests.Common;

/// <summary>
/// Unit tests for the defaults of the page every paged Storage list returns.
/// </summary>
[TestClass]
[TestCategory("Unit")]
public class PageTests
{
[TestMethod]
public void Page_ShouldHaveNoItem_GivenNoneSet() =>
new Page<string>().Items.Should().BeEmpty("a page is never null, so callers can iterate it without a check");
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ListVectorBucketsApprovalTests : RequestApprovalFixture
public async Task ListVectorBucketsRequest_ShouldSerializeToExpectedPayload()
{
this.RespondWith(EmptyPage);
await this.Client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { Prefix = "embeddings-", MaxResults = 50, NextToken = "embeddings-v1" });
await this.Client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { Prefix = "embeddings-", PageSize = 50, NextPageToken = "embeddings-v1" });
await this.Verify(this.EmittedRequestBody).UseDirectory("Data");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Storage.Tests.Support;
using Supabase.Storage;
using Supabase.Storage.Exceptions;
using Supabase.Storage.VectorBuckets.Common;
using Supabase.Storage.Common;
using Supabase.Storage.VectorBuckets.ListBuckets;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
Expand Down Expand Up @@ -61,7 +61,7 @@ public async Task ListVectorBucketsAsync_ShouldPostAnEmptyBody_GivenNoOptions()
public async Task ListVectorBucketsAsync_ShouldSendThePrefixAndPaging_GivenOptions()
{
this.Respond(200, FirstPageBody);
await this.client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { Prefix = "embeddings-", MaxResults = 2, NextToken = "embeddings-a" });
await this.client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { Prefix = "embeddings-", PageSize = 2, NextPageToken = "embeddings-a" });
this.server.LogEntries.Should().ContainSingle().Which.RequestMessage!.Body
.Should().Be("{\"maxResults\":2,\"nextToken\":\"embeddings-a\",\"prefix\":\"embeddings-\"}", "the ListVectorBuckets schema names them maxResults, nextToken and prefix");
}
Expand All @@ -70,22 +70,22 @@ public async Task ListVectorBucketsAsync_ShouldSendThePrefixAndPaging_GivenOptio
public async Task ListVectorBucketsAsync_ShouldReturnThePage()
{
this.Respond(200, FirstPageBody);
(await this.client.Vectors.ListVectorBucketsAsync()).Should().BeEquivalentTo(new VectorListPage<VectorBucketSummary>
(await this.client.Vectors.ListVectorBucketsAsync()).Should().BeEquivalentTo(new Page<VectorBucketSummary>
{
Items = new[]
{
new VectorBucketSummary { VectorBucketName = "embeddings-v1", CreatedAt = DateTimeOffset.FromUnixTimeSeconds(FirstCreationTime) },
new VectorBucketSummary { VectorBucketName = "embeddings-v2", CreatedAt = DateTimeOffset.FromUnixTimeSeconds(SecondCreationTime) },
},
NextToken = "embeddings-v2",
NextPageToken = "embeddings-v2",
}, options => options.WithStrictOrdering(), "the service lists buckets by name with creation times in Unix seconds and a token while more remain");
}

[TestMethod]
public async Task ListVectorBucketsAsync_ShouldReturnNoNextToken_GivenTheLastPage()
public async Task ListVectorBucketsAsync_ShouldReturnNoNextPageToken_GivenTheLastPage()
{
this.Respond(200, $"{{\"vectorBuckets\":[{{\"vectorBucketName\":\"embeddings-v3\",\"creationTime\":{FirstCreationTime}}}]}}");
(await this.client.Vectors.ListVectorBucketsAsync()).NextToken
(await this.client.Vectors.ListVectorBucketsAsync()).NextPageToken
.Should().BeNull("the service omits the token when no bucket remains");
}

Expand Down Expand Up @@ -126,10 +126,10 @@ public async Task ListVectorBucketsAsync_ShouldThrowStorageException_GivenAServi
}

[TestMethod]
public async Task ListVectorBucketsAsync_ShouldClassifyAsInvalidInput_GivenAnOutOfRangeMaxResults()
public async Task ListVectorBucketsAsync_ShouldClassifyAsInvalidInput_GivenAnOutOfRangePageSize()
{
this.Respond(400, "{\"statusCode\":\"400\",\"error\":\"Error\",\"message\":\"body/maxResults must be >= 1\",\"code\":\"InvalidRequest\"}");
(await FluentActions.Awaiting(() => this.client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { MaxResults = 0 }))
(await FluentActions.Awaiting(() => this.client.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { PageSize = 0 }))
.Should().ThrowAsync<SupabaseStorageException>())
.Which.Reason.Should().Be(FailureHint.Reason.InvalidInput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ public async Task ListVectorBucketsAsync_ShouldListOnlyMatchingBucketsByName_Giv
using (new AssertionScope())
{
page.Items.Select(bucket => bucket.VectorBucketName).Should().Equal(this.names, "only names starting with the prefix match, sorted by name");
page.NextToken.Should().BeNull("every match fits on the default page");
page.NextPageToken.Should().BeNull("every match fits on the default page");
page.Items.Should().OnlyContain(bucket => bucket.CreatedAt.Year >= 2025, "the service reports the creation time");
}
}

[TestMethod]
public async Task ListVectorBucketsAsync_ShouldPageThroughEveryBucket_GivenMaxResults()
public async Task ListVectorBucketsAsync_ShouldPageThroughEveryBucket_GivenAPageSize()
{
var options = new ListVectorBucketsOptions { Prefix = this.prefix, MaxResults = 2 };
var options = new ListVectorBucketsOptions { Prefix = this.prefix, PageSize = 2 };
var first = await this.Storage.Vectors.ListVectorBucketsAsync(options);
var last = await this.Storage.Vectors.ListVectorBucketsAsync(options with { NextToken = first.NextToken });
var last = await this.Storage.Vectors.ListVectorBucketsAsync(options with { NextPageToken = first.NextPageToken });
using (new AssertionScope())
{
first.Items.Select(bucket => bucket.VectorBucketName).Should().Equal(this.names.Take(2));
last.Items.Select(bucket => bucket.VectorBucketName).Should().Equal(new[] { this.names[2] }, "the token resumes after the previous page");
last.NextToken.Should().BeNull("no bucket remains after the last page");
last.NextPageToken.Should().BeNull("no bucket remains after the last page");
}
}

Expand All @@ -70,9 +70,9 @@ public async Task ListVectorBucketsAsync_ShouldReturnNoBucket_GivenAPrefixNothin
}

[TestMethod]
public async Task ListVectorBucketsAsync_ShouldThrowInvalidInput_GivenAnOutOfRangeMaxResults()
public async Task ListVectorBucketsAsync_ShouldThrowInvalidInput_GivenAnOutOfRangePageSize()
{
var thrown = await FluentActions.Awaiting(() => this.Storage.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { MaxResults = 0 }))
var thrown = await FluentActions.Awaiting(() => this.Storage.Vectors.ListVectorBucketsAsync(new ListVectorBucketsOptions { PageSize = 0 }))
.Should().ThrowAsync<SupabaseStorageException>("the service accepts 1 to 500 results per page");
using (new AssertionScope())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ListVectorIndexesApprovalTests : RequestApprovalFixture
public async Task ListIndexesRequest_ShouldSerializeToExpectedPayload()
{
this.RespondWith(EmptyPage);
await this.Client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { Prefix = "docs-", MaxResults = 50, NextToken = "docs-v1" });
await this.Client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { Prefix = "docs-", PageSize = 50, NextPageToken = "docs-v1" });
await this.Verify(this.EmittedRequestBody).UseDirectory("Data");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Storage.Tests.Support;
using Supabase.Storage;
using Supabase.Storage.Exceptions;
using Supabase.Storage.VectorBuckets.Common;
using Supabase.Storage.Common;
using Supabase.Storage.VectorBuckets.ListIndexes;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
Expand Down Expand Up @@ -61,7 +61,7 @@ public async Task ListIndexesAsync_ShouldPostOnlyTheBucketName_GivenNoOptions()
public async Task ListIndexesAsync_ShouldSendThePrefixAndPaging_GivenOptions()
{
this.Respond(200, FirstPageBody);
await this.client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { Prefix = "docs-", MaxResults = 2, NextToken = "docs-a" });
await this.client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { Prefix = "docs-", PageSize = 2, NextPageToken = "docs-a" });
this.server.LogEntries.Should().ContainSingle().Which.RequestMessage!.Body
.Should().Be("{\"vectorBucketName\":\"embeddings-prod\",\"maxResults\":2,\"nextToken\":\"docs-a\",\"prefix\":\"docs-\"}", "the ListIndexes schema names them maxResults, nextToken and prefix");
}
Expand All @@ -70,22 +70,22 @@ public async Task ListIndexesAsync_ShouldSendThePrefixAndPaging_GivenOptions()
public async Task ListIndexesAsync_ShouldReturnThePage()
{
this.Respond(200, FirstPageBody);
(await this.client.Vectors.From("embeddings-prod").ListIndexesAsync()).Should().BeEquivalentTo(new VectorListPage<VectorIndexSummary>
(await this.client.Vectors.From("embeddings-prod").ListIndexesAsync()).Should().BeEquivalentTo(new Page<VectorIndexSummary>
{
Items = new[]
{
new VectorIndexSummary { IndexName = "docs-v1", CreatedAt = DateTimeOffset.FromUnixTimeSeconds(FirstCreationTime) },
new VectorIndexSummary { IndexName = "docs-v2", CreatedAt = DateTimeOffset.FromUnixTimeSeconds(SecondCreationTime) },
},
NextToken = "docs-v2",
NextPageToken = "docs-v2",
}, options => options.WithStrictOrdering(), "the service lists indexes by name with creation times in Unix seconds and a token while more remain");
}

[TestMethod]
public async Task ListIndexesAsync_ShouldReturnNoNextToken_GivenTheLastPage()
public async Task ListIndexesAsync_ShouldReturnNoNextPageToken_GivenTheLastPage()
{
this.Respond(200, $"{{\"indexes\":[{{\"indexName\":\"docs-v3\",\"vectorBucketName\":\"embeddings-prod\",\"creationTime\":{FirstCreationTime}}}]}}");
(await this.client.Vectors.From("embeddings-prod").ListIndexesAsync()).NextToken
(await this.client.Vectors.From("embeddings-prod").ListIndexesAsync()).NextPageToken
.Should().BeNull("the service omits the token when no index remains");
}

Expand Down Expand Up @@ -126,10 +126,10 @@ public async Task ListIndexesAsync_ShouldThrowStorageException_GivenAServiceErro
}

[TestMethod]
public async Task ListIndexesAsync_ShouldClassifyAsInvalidInput_GivenAnOutOfRangeMaxResults()
public async Task ListIndexesAsync_ShouldClassifyAsInvalidInput_GivenAnOutOfRangePageSize()
{
this.Respond(400, "{\"statusCode\":\"400\",\"error\":\"Error\",\"message\":\"body/maxResults must be >= 1\",\"code\":\"InvalidRequest\"}");
(await FluentActions.Awaiting(() => this.client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { MaxResults = 0 }))
(await FluentActions.Awaiting(() => this.client.Vectors.From("embeddings-prod").ListIndexesAsync(new ListVectorIndexesOptions { PageSize = 0 }))
.Should().ThrowAsync<SupabaseStorageException>())
.Which.Reason.Should().Be(FailureHint.Reason.InvalidInput);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ public async Task ListIndexesAsync_ShouldListOnlyMatchingIndexes_GivenAPrefix()
}

[TestMethod]
public async Task ListIndexesAsync_ShouldPageThroughEveryIndex_GivenMaxResults()
public async Task ListIndexesAsync_ShouldPageThroughEveryIndex_GivenAPageSize()
{
var bucket = this.Storage.Vectors.From(this.VectorBucketName);
var first = await bucket.ListIndexesAsync(new ListVectorIndexesOptions { MaxResults = 2 });
var last = await bucket.ListIndexesAsync(new ListVectorIndexesOptions { MaxResults = 2, NextToken = first.NextToken });
var options = new ListVectorIndexesOptions { PageSize = 2 };
var first = await bucket.ListIndexesAsync(options);
var last = await bucket.ListIndexesAsync(options with { NextPageToken = first.NextPageToken });
using (new AssertionScope())
{
first.Items.Select(index => index.IndexName).Should().Equal(new[] { "docs-v1", "docs-v2" });
last.Items.Select(index => index.IndexName).Should().Equal(new[] { "notes-v1" }, "the token resumes after the previous page");
last.NextToken.Should().BeNull("no index remains after the last page");
last.NextPageToken.Should().BeNull("no index remains after the last page");
}
}

Expand All @@ -69,9 +70,9 @@ public async Task ListIndexesAsync_ShouldReturnNoIndex_GivenABucketThatDoesNotEx
}

[TestMethod]
public async Task ListIndexesAsync_ShouldThrowInvalidInput_GivenAnOutOfRangeMaxResults()
public async Task ListIndexesAsync_ShouldThrowInvalidInput_GivenAnOutOfRangePageSize()
{
var thrown = await FluentActions.Awaiting(() => this.Storage.Vectors.From(this.VectorBucketName).ListIndexesAsync(new ListVectorIndexesOptions { MaxResults = 0 }))
var thrown = await FluentActions.Awaiting(() => this.Storage.Vectors.From(this.VectorBucketName).ListIndexesAsync(new ListVectorIndexesOptions { PageSize = 0 }))
.Should().ThrowAsync<SupabaseStorageException>("the service accepts 1 to 500 results per page");
using (new AssertionScope())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public async Task ListVectorsRequest_ShouldSendEveryOption_GivenAllOptions()
this.RespondWith("{\"vectors\":[]}");
await this.Client.Vectors.From("embeddings-prod").Index("docs-v1").ListVectorsAsync(new ListVectorsOptions
{
MaxResults = 100,
NextToken = "doc-100",
PageSize = 100,
NextPageToken = "doc-100",
Include = VectorContent.Data | VectorContent.Metadata,
Segment = new VectorSegment(1, 4),
});
Expand Down
Loading