Skip to content

Commit

Permalink
feat: add ability to list files in bucket and fix release workflow (#20)
Browse files Browse the repository at this point in the history
* feat: add ability to list blobs in bucket
* ci: update release workflow to add version tag
  • Loading branch information
HomelessDinosaur committed Mar 13, 2024
1 parent bdf2be4 commit c89325e
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
- uses: dart-lang/setup-dart@v1
- name: Install dependencies
run: dart pub get
- name: Add version
env:
TAG_VERSION: ${{ github.event.release.tag_name }}
run: echo "\n\nversion: ${TAG_VERSION##v}" >> pubspec.yaml
- name: Check Publish Warnings
run: dart pub publish --dry-run
- name: Publish
Expand Down
3 changes: 1 addition & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ environment:
sdk: ^3.2.5

dependencies:
nitric_sdk:
path: ../
nitric_sdk: ^1.0.0
uuid: ^4.3.3

dev_dependencies:
Expand Down
10 changes: 10 additions & 0 deletions lib/src/api/bucket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ class Bucket {
return File(this, key);
}

/// Get a list of references to the files in the bucket. Optionally supply a [prefix] to filter by.
Future<List<File>> files({String prefix = ""}) async {
final request =
$p.StorageListBlobsRequest(bucketName: name, prefix: prefix);

var resp = await _storageClient.listBlobs(request);

return resp.blobs.map((blob) => File(this, blob.key)).toList();
}

/// Create a blob event subscription triggered on the [blobEventType] filtered by files that match the [keyPrefixFilter].
Future<void> on(BlobEventType blobEventType, String keyPrefixFilter,
BlobEventHandler handler) async {
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
name: nitric_sdk
description: A Dart SDK for creating Nitric applications
version: 1.0.0
repository: https://github.com/nitrictech/dart_sdk

environment:
Expand Down
43 changes: 43 additions & 0 deletions test/src/api/bucket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,49 @@ void main() {
expect(file.key, "fileName");
});

test('Test get list of files with no prefix filter', () async {
var req = StorageListBlobsRequest(bucketName: "bucketName", prefix: "");

var resp = StorageListBlobsResponse(
blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]);

when(() => storageClient.listBlobs(req))
.thenAnswer((_) => MockResponseFuture.value(resp));

var bucket = Bucket("bucketName", client: storageClient);

var blobs = await bucket.files();

verify(() => storageClient.listBlobs(req)).called(1);

expect(blobs.length, 3);
expect(blobs[0].key, "blob-a");
expect(blobs[1].key, "blob-b");
expect(blobs[2].key, "blob-c");
});

test('Test get list of files with prefix filter', () async {
var req =
StorageListBlobsRequest(bucketName: "bucketName", prefix: "blob-");

var resp = StorageListBlobsResponse(
blobs: [Blob(key: "blob-a"), Blob(key: "blob-b"), Blob(key: "blob-c")]);

when(() => storageClient.listBlobs(req))
.thenAnswer((_) => MockResponseFuture.value(resp));

var bucket = Bucket("bucketName", client: storageClient);

var blobs = await bucket.files(prefix: "blob-");

verify(() => storageClient.listBlobs(req)).called(1);

expect(blobs.length, 3);
expect(blobs[0].key, "blob-a");
expect(blobs[1].key, "blob-b");
expect(blobs[2].key, "blob-c");
});

test('Test write to file', () async {
var req = StorageWriteRequest(
bucketName: "bucketName",
Expand Down

0 comments on commit c89325e

Please sign in to comment.