platform/packages/configuration/test/all_test.dart

80 lines
2.5 KiB
Dart
Raw Normal View History

2020-05-03 15:24:22 +00:00
import 'dart:async';
2021-05-14 11:27:54 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_configuration/angel3_configuration.dart';
import 'package:angel3_pretty_logging/angel3_pretty_logging.dart';
2017-09-25 13:50:56 +00:00
import 'package:file/local.dart';
2018-12-31 15:41:56 +00:00
import 'package:io/ansi.dart';
2020-05-04 15:59:33 +00:00
import 'package:logging/logging.dart';
2016-04-22 01:17:31 +00:00
import 'package:test/test.dart';
2020-05-03 15:24:22 +00:00
Future<void> main() async {
2021-05-14 11:27:54 +00:00
Logger.root.onRecord.listen(prettyLog);
2020-05-04 15:59:33 +00:00
2016-04-22 01:17:31 +00:00
// Note: Set ANGEL_ENV to 'development'
2020-05-04 15:59:33 +00:00
var app = Angel(logger: Logger('angel_configuration'));
2017-09-25 13:50:56 +00:00
var fileSystem = const LocalFileSystem();
await app.configure(configuration(
fileSystem,
directoryPath: './test/config',
));
2016-04-22 01:17:31 +00:00
2018-12-31 15:41:56 +00:00
test('standalone', () async {
var config = await loadStandaloneConfiguration(
fileSystem,
directoryPath: './test/config',
onWarning: (msg) {
print(yellow.wrap('STANDALONE WARNING: $msg'));
},
);
print('Standalone: $config');
expect(config, {
2020-05-03 15:24:22 +00:00
'angel': {'framework': 'cool'},
'must_be_null': null,
'artist': 'Timberlake',
'included': true,
2020-05-03 15:24:22 +00:00
'merge': {'map': true, 'hello': 'world'},
'set_via': 'default',
'hello': 'world',
'foo': {'version': 'bar'}
2018-12-31 15:41:56 +00:00
});
});
test('obeys included paths', () async {
expect(app.configuration['included'], true);
});
2016-05-02 23:35:21 +00:00
test('can load based on ANGEL_ENV', () async {
2017-09-25 13:50:56 +00:00
expect(app.configuration['hello'], equals('world'));
expect(app.configuration['foo']['version'], equals('bar'));
2016-04-22 01:17:31 +00:00
});
test('will load default.yaml if exists', () {
2020-05-03 15:24:22 +00:00
expect(app.configuration['set_via'], equals('default'));
2017-06-14 18:48:13 +00:00
});
test('will load .env if exists', () {
2017-09-25 13:50:56 +00:00
expect(app.configuration['artist'], 'Timberlake');
expect(app.configuration['angel'], {'framework': 'cool'});
2016-04-22 01:17:31 +00:00
});
2017-06-14 18:48:13 +00:00
test('non-existent environment defaults to null', () {
2017-09-25 13:50:56 +00:00
expect(app.configuration.keys, contains('must_be_null'));
expect(app.configuration['must_be_null'], null);
2017-06-14 18:48:13 +00:00
});
2016-04-22 01:17:31 +00:00
2016-05-02 23:35:21 +00:00
test('can override ANGEL_ENV', () async {
2017-09-25 13:50:56 +00:00
await app.configure(configuration(fileSystem,
2016-04-22 01:17:31 +00:00
directoryPath: './test/config', overrideEnvironmentName: 'override'));
2017-09-25 13:50:56 +00:00
expect(app.configuration['hello'], equals('goodbye'));
expect(app.configuration['foo']['version'], equals('baz'));
2016-04-22 01:17:31 +00:00
});
2016-09-19 20:24:26 +00:00
2017-08-16 00:29:13 +00:00
test('merges configuration', () async {
2017-09-25 13:50:56 +00:00
await app.configure(configuration(fileSystem,
2017-08-16 00:29:13 +00:00
directoryPath: './test/config', overrideEnvironmentName: 'override'));
2017-09-25 13:50:56 +00:00
expect(app.configuration['merge'], {'map': true, 'hello': 'goodbye'});
2017-08-16 00:29:13 +00:00
});
2016-09-19 20:24:26 +00:00
}