platform/packages/configuration/test/all_test.dart
2024-10-12 18:45:27 -07:00

79 lines
2.5 KiB
Dart

import 'dart:async';
import 'package:protevus_framework/protevus_framework.dart';
import 'package:protevus_configuration/protevus_configuration.dart';
import 'package:belatuk_pretty_logging/belatuk_pretty_logging.dart';
import 'package:file/local.dart';
import 'package:io/ansi.dart';
import 'package:logging/logging.dart';
import 'package:test/test.dart';
Future<void> main() async {
Logger.root.onRecord.listen(prettyLog);
// Note: Set ANGEL_ENV to 'development'
var app = Protevus(logger: Logger('angel_configuration'));
var fileSystem = const LocalFileSystem();
await app.configure(configuration(
fileSystem,
directoryPath: './test/config',
));
test('standalone', () async {
var config = await loadStandaloneConfiguration(
fileSystem,
directoryPath: './test/config',
onWarning: (msg) {
print(yellow.wrap('STANDALONE WARNING: $msg'));
},
);
print('Standalone: $config');
expect(config, {
'protevus': {'framework': 'cool'},
'must_be_null': null,
'artist': 'Timberlake',
'included': true,
'merge': {'map': true, 'hello': 'world'},
'set_via': 'default',
'hello': 'world',
'foo': {'version': 'bar'}
});
});
test('obeys included paths', () async {
expect(app.configuration['included'], true);
});
test('can load based on ANGEL_ENV', () async {
expect(app.configuration['hello'], equals('world'));
expect(app.configuration['foo']['version'], equals('bar'));
});
test('will load default.yaml if exists', () {
expect(app.configuration['set_via'], equals('default'));
});
test('will load .env if exists', () {
expect(app.configuration['artist'], 'Timberlake');
expect(app.configuration['protevus'], {'framework': 'cool'});
});
test('non-existent environment defaults to null', () {
expect(app.configuration.keys, contains('must_be_null'));
expect(app.configuration['must_be_null'], null);
});
test('can override ANGEL_ENV', () async {
await app.configure(configuration(fileSystem,
directoryPath: './test/config', overrideEnvironmentName: 'override'));
expect(app.configuration['hello'], equals('goodbye'));
expect(app.configuration['foo']['version'], equals('baz'));
});
test('merges configuration', () async {
await app.configure(configuration(fileSystem,
directoryPath: './test/config', overrideEnvironmentName: 'override'));
expect(app.configuration['merge'], {'map': true, 'hello': 'goodbye'});
});
}