It works baby, seems like timing could be improved or something, but it freakin works
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:mumbullet/src/config/config.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('AppConfig', () {
|
||||
late File tempConfigFile;
|
||||
|
||||
setUp(() {
|
||||
tempConfigFile = File('test_config.json');
|
||||
tempConfigFile.writeAsStringSync('''
|
||||
{
|
||||
"mumble": {
|
||||
"server": "test.server.com",
|
||||
"port": 12345,
|
||||
"username": "TestBot",
|
||||
"password": "testpass",
|
||||
"channel": "Root"
|
||||
},
|
||||
"bot": {
|
||||
"command_prefix": "?",
|
||||
"default_permission_level": 1,
|
||||
"max_queue_size": 100,
|
||||
"cache_directory": "./test_cache",
|
||||
"max_cache_size_gb": 2.5
|
||||
},
|
||||
"dashboard": {
|
||||
"port": 9090,
|
||||
"admin_username": "testadmin",
|
||||
"admin_password": "testpassword"
|
||||
}
|
||||
}
|
||||
''');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
if (tempConfigFile.existsSync()) {
|
||||
tempConfigFile.deleteSync();
|
||||
}
|
||||
});
|
||||
|
||||
test('should load configuration from file', () {
|
||||
final config = AppConfig.fromFile(tempConfigFile.path);
|
||||
|
||||
expect(config.mumble.server, equals('test.server.com'));
|
||||
expect(config.mumble.port, equals(12345));
|
||||
expect(config.mumble.username, equals('TestBot'));
|
||||
expect(config.mumble.password, equals('testpass'));
|
||||
expect(config.mumble.channel, equals('TestChannel'));
|
||||
|
||||
expect(config.bot.commandPrefix, equals('?'));
|
||||
expect(config.bot.defaultPermissionLevel, equals(1));
|
||||
expect(config.bot.maxQueueSize, equals(100));
|
||||
expect(config.bot.cacheDirectory, equals('./test_cache'));
|
||||
expect(config.bot.maxCacheSizeGb, equals(2.5));
|
||||
|
||||
expect(config.dashboard.port, equals(9090));
|
||||
expect(config.dashboard.adminUsername, equals('testadmin'));
|
||||
expect(config.dashboard.adminPassword, equals('testpassword'));
|
||||
});
|
||||
|
||||
test('should throw exception for non-existent file', () {
|
||||
expect(() => AppConfig.fromFile('non_existent_file.json'), throwsA(isA<FileSystemException>()));
|
||||
});
|
||||
|
||||
test('should validate configuration', () {
|
||||
final config = AppConfig.fromFile(tempConfigFile.path);
|
||||
|
||||
// Valid configuration should not throw
|
||||
expect(() => config.validate(), returnsNormally);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user