From 7e4a09d370d321ffad54ebae3f8e04e8e4eefdd2 Mon Sep 17 00:00:00 2001 From: philenius <philenius@users.noreply.github.com> Date: Tue, 24 Nov 2020 22:56:10 +0100 Subject: [PATCH] add unit tests for listBuckets() --- lib/minio.dart | 4 +-- test/minio_dart_test.dart | 71 ++++++++++++++++++++++++++++++++++----- 2 files changed, 63 insertions(+), 12 deletions(-) diff --git a/lib/minio.dart b/lib/minio.dart index 087f4a5..113198e 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 f6775d5..cc066cf 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, + ); -- GitLab