platform/packages/configuration/test/all_test.dart

69 lines
2.1 KiB
Dart
Raw Normal View History

2016-04-22 01:17:31 +00:00
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_configuration/angel_configuration.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';
2016-04-22 01:17:31 +00:00
import 'package:test/test.dart';
2016-05-02 23:35:21 +00:00
main() async {
2016-04-22 01:17:31 +00:00
// Note: Set ANGEL_ENV to 'development'
2017-06-14 18:48:13 +00:00
var app = new Angel();
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, {
"angel": {"framework": "cool"},
"must_be_null": null,
"artist": "Timberlake",
"merge": {"map": true, "hello": "world"},
"set_via": "default",
"hello": "world",
"foo": {"version": "bar"}
});
});
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', () {
2017-09-25 13:50:56 +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
}