Skip to content

Commit 1ccddba

Browse files
committed
Update tests to use latest storage-server from github
1 parent ed21fa3 commit 1ccddba

File tree

10 files changed

+43
-160
lines changed

10 files changed

+43
-160
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
run: dotnet build --configuration Release --no-restore
3131

3232
- name: Initialize Testing Stack
33-
run: docker-compose up -d
33+
run: chmod +x ./prepare-infra.sh && ./prepare-infra.sh && sleep 5
3434

3535
- name: Test
3636
run: dotnet test --no-restore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ autom4te.cache/
1111
tarballs/
1212
test-results/
1313

14+
.storage-server
1415
.env
1516

1617
# Mac bundle stuff

Storage/Exceptions/FailureHint.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ public static Reason DetectReason(SupabaseStorageException storageException)
2222

2323
return storageException.StatusCode switch
2424
{
25-
400 when storageException.Content.Contains("Invalid") => InvalidInput,
26-
400 when storageException.Content.Contains("authorization") => NotAuthorized,
27-
400 when storageException.Content.Contains("malformed") => NotAuthorized,
28-
400 when storageException.Content.Contains("invalid signature") => NotAuthorized,
25+
400 when storageException.Content.ToLower().Contains("authorization") => NotAuthorized,
26+
400 when storageException.Content.ToLower().Contains("malformed") => NotAuthorized,
27+
400 when storageException.Content.ToLower().Contains("invalid signature") => NotAuthorized,
28+
400 when storageException.Content.ToLower().Contains("invalid") => InvalidInput,
2929
401 => NotAuthorized,
30-
404 when storageException.Content.Contains("Not found") => NotFound,
31-
409 when storageException.Content.Contains("exists") => AlreadyExists,
30+
404 when storageException.Content.ToLower().Contains("not found") => NotFound,
31+
409 when storageException.Content.ToLower().Contains("exists") => AlreadyExists,
3232
500 => Internal,
3333
_ => Unknown
3434
};

StorageTests/Helpers.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ namespace StorageTests
55
{
66
public static class Helpers
77
{
8-
public static string SupabaseUrl => Environment.GetEnvironmentVariable("SUPABASE_URL") ?? "http://localhost:3000";
9-
public static string ServiceKey => Environment.GetEnvironmentVariable("SUPABASE_SERVICE_KEY");
10-
public static string PublicKey => Environment.GetEnvironmentVariable("SUPABASE_PUBLIC_KEY");
8+
public static string SupabaseUrl => "http://localhost:5000";
9+
public static string ServiceKey => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic2VydmljZV9yb2xlIiwiaWF0IjoxNjEzNTMxOTg1LCJleHAiOjE5MjkxMDc5ODV9.th84OKK0Iz8QchDyXZRrojmKSEZ-OuitQm_5DvLiSIc";
10+
public static string PublicKey => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwic3ViIjoiMzE3ZWFkY2UtNjMxYS00NDI5LWEwYmItZjE5YTdhNTE3YjRhIiwiZW1haWwiOiJpbmlhbit0ZXN0MUBzdXBhYmFzZS5pbyIsImV4cCI6MTkzOTEwNzk4NSwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1haWwifSwidXNlcl9tZXRhZGF0YSI6e30sInJvbGUiOiJhdXRoZW50aWNhdGVkIn0.E-x3oYcHIjFCdUO1M3wKDl1Ln32mik0xdHT2PjrvN70";
1111

12-
public static string StorageUrl => $"{SupabaseUrl}/storage/v1";
12+
public static string StorageUrl => $"{SupabaseUrl}";
1313

14-
public static Supabase.Storage.Client GetClient()
14+
public static Supabase.Storage.Client GetServiceClient()
1515
{
1616
return new Supabase.Storage.Client(StorageUrl, new Dictionary<string, string>
1717
{

StorageTests/StorageBucketAnonTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StorageTests;
1111
[TestClass]
1212
public class StorageBucketAnonTests
1313
{
14-
private Client AdminStorage => Helpers.GetClient();
14+
private Client AdminStorage => Helpers.GetServiceClient();
1515
private Client Storage => Helpers.GetPublicClient();
1616

1717
[TestMethod("Bucket: Returns empty when attempting to List")]

StorageTests/StorageBucketTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace StorageTests;
1111
[TestClass]
1212
public class StorageBucketTests
1313
{
14-
Client Storage => Helpers.GetClient();
14+
Client Storage => Helpers.GetServiceClient();
1515

1616
[TestMethod("Bucket: List")]
1717
public async Task List()

StorageTests/StorageFileAnonTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace StorageTests;
1414
[TestClass]
1515
public class StorageFileAnonTests
1616
{
17-
Client AdminStorage => Helpers.GetClient();
17+
Client AdminStorage => Helpers.GetServiceClient();
1818
private Client Storage => Helpers.GetPublicClient();
1919

2020
private string _bucketId = string.Empty;

StorageTests/StorageFileTests.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace StorageTests;
1313
[TestClass]
1414
public class StorageFileTests
1515
{
16-
Client Storage => Helpers.GetClient();
16+
Client Storage => Helpers.GetServiceClient();
1717

1818
private string _bucketId = string.Empty;
1919
private IStorageFileApi<FileObject> _bucket = null!;
@@ -23,7 +23,8 @@ public async Task InitializeTest()
2323
{
2424
_bucketId = Guid.NewGuid().ToString();
2525

26-
if (_bucket == null && await Storage.GetBucket(_bucketId) == null)
26+
var exists = await Storage.GetBucket(_bucketId);
27+
if (exists == null)
2728
{
2829
await Storage.CreateBucket(_bucketId, new BucketUpsertOptions { Public = true });
2930
}
@@ -34,20 +35,17 @@ public async Task InitializeTest()
3435
[TestCleanup]
3536
public async Task TestCleanup()
3637
{
37-
if (_bucket != null)
38-
{
39-
var files = await _bucket.List();
40-
41-
Assert.IsNotNull(files);
38+
var files = await _bucket.List();
4239

43-
foreach (var file in files)
44-
{
45-
if (file.Name is not null)
46-
await _bucket.Remove(new List<string> { file.Name });
47-
}
40+
Assert.IsNotNull(files);
4841

49-
await Storage.DeleteBucket(_bucketId);
42+
foreach (var file in files)
43+
{
44+
if (file.Name is not null)
45+
await _bucket.Remove(new List<string> { file.Name });
5046
}
47+
48+
await Storage.DeleteBucket(_bucketId);
5149
}
5250

5351
[TestMethod("File: Upload File")]

docker-compose.yml

Lines changed: 0 additions & 132 deletions
This file was deleted.

prepare-infra.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
git clone https://github.com/supabase/storage .storage-server
4+
cd .storage-server
5+
6+
git fetch --all --tags
7+
git checkout tags/v1.0.10 -b v1.0.10-branch
8+
9+
cp .env.sample .env && cp .env.test.sample .env.test
10+
11+
npm install
12+
npm run infra:restart
13+
npm run build
14+
15+
cmd="npm run start";
16+
eval "${cmd}" &>/dev/null & disown;

0 commit comments

Comments
 (0)