diff --git a/lib/minio.dart b/lib/minio.dart index 087f4a5435cd5d8f241b6f51e05aa3a05cbc7944..113198ef31fe5e9a2a581dcb2ec1d5b10ac4f3a7 100644 --- a/lib/minio.dart +++ b/lib/minio.dart @@ -1,8 +1,6 @@ -/// Support for doing something awesome. -/// -/// More dartdocs go here. library minio; export 'src/minio.dart'; +export 'src/minio_errors.dart'; // TODO: Export any libraries intended for clients of this package. diff --git a/test/minio_dart_test.dart b/test/minio_dart_test.dart index f6775d5abcf6a772254b007b6870b59be68f6721..cc066cf05713e9b39ede297e02d059a569471ea3 100644 --- a/test/minio_dart_test.dart +++ b/test/minio_dart_test.dart @@ -1,14 +1,67 @@ +import 'package:minio/minio.dart'; +import 'package:test/test.dart'; void main() { - // group('A group of tests', () { - // Awesome awesome; + group('listBuckets', () { + test('listBuckets() succeeds', () async { + final minio = _getClient(); - // setUp(() { - // awesome = Awesome(); - // }); + expect(() async => await minio.listBuckets(), returnsNormally); + }); - // test('First Test', () { - // expect(awesome.isAwesome, isTrue); - // }); - // }); + test('listBuckets() fails due to wrong access key', () async { + final minio = _getClient(accessKey: 'incorrect-access-key'); + + expect( + () async => await minio.listBuckets(), + throwsA( + isA<MinioError>().having( + (e) => e.message, + 'message', + 'The Access Key Id you provided does not exist in our records.', + ), + ), + ); + }); + + test('listBuckets() fails due to wrong secret key', () async { + final minio = _getClient(secretKey: 'incorrect-secret-key'); + + expect( + () async => await minio.listBuckets(), + throwsA( + isA<MinioError>().having( + (e) => e.message, + 'message', + 'The request signature we calculated does not match the signature you provided. Check your key and signing method.', + ), + ), + ); + }); + }); } + +/// Initializes an instance of [Minio] with per default valid configuration. +/// +/// Don't worry, these credentials for MinIO are publicly available and +/// connect only to the MinIO demo server at `play.minio.io`. +Minio _getClient({ + String endpoint = 'play.minio.io', + int port = 443, + bool useSSL = true, + String accessKey = 'Q3AM3UQ867SPQQA43P2F', + String secretKey = 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG', + String sessionToken = '', + String region = 'us-east-1', + bool enableTrace = false, +}) => + Minio( + endPoint: endpoint, + port: port, + useSSL: useSSL, + accessKey: accessKey, + secretKey: secretKey, + sessionToken: sessionToken, + region: region, + enableTrace: enableTrace, + );