From 549cc6bdddda38ce07cb03411913a0f5a2690538 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Wed, 24 Mar 2021 14:17:47 +0700 Subject: [PATCH] Add example and add more tests and fixed function --- example/example.dart | 10 +++++++++- test/config_test.dart | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/example/example.dart b/example/example.dart index 24a92d2..1ad7ed4 100644 --- a/example/example.dart +++ b/example/example.dart @@ -1,5 +1,6 @@ import 'package:configurable/dotenv_configuration_provider.dart'; import 'package:configurable/simple_configuration_provider.dart'; +import 'package:configurable/system_config.dart'; void main() { var key = 'app.name'; @@ -7,9 +8,16 @@ void main() { // in-memory provider (built-in) var simpleProvider = SimpleConfigurationProvider(); + SystemConfig.setProvider(simpleProvider); + var result1 = SystemConfig.getOrNull(key, defaultValue: value); + // output: CUBETIQ Solution + print(result1); // dotenv provider (from file .env) var dotenvProvider = DotenvConfigurationProvider(); + SystemConfig.setProvider(dotenvProvider); + var result2 = SystemConfig.getOrNull('HOME'); - + // output: user's home directory + print(result2); } \ No newline at end of file diff --git a/test/config_test.dart b/test/config_test.dart index e420b67..b79cff1 100644 --- a/test/config_test.dart +++ b/test/config_test.dart @@ -1,4 +1,4 @@ -import 'package:configurable/configurable.dart' show getConfigOrNull; +import 'package:configurable/configurable.dart' show getConfigOrNull, hasConfigkey; import 'package:configurable/dotenv_configuration_provider.dart'; import 'package:configurable/system_config.dart'; import 'package:test/test.dart'; @@ -33,6 +33,7 @@ void main() { var result = getConfigOrNull(key, defaultValue: value); expect(value, equals(result)); + expect(true, equals(hasConfigkey(key))); expect(value, equals(getConfigOrNull(key))); }); }