mnemosyne/t/config.t

41 lines
1.1 KiB
Perl

#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;
use File::Temp qw(tempfile);
use FindBin qw($RealBin);
use lib "$RealBin/../lib";
use_ok('Mnemosyne::Config');
my (undef, $tmp) = tempfile(SUFFIX => '.conf', UNLINK => 1);
open my $fh, '>', $tmp or die $!;
print $fh <<'END';
[bot]
token = abc123
webhook_secret = secret456
allowed_chat_ids = 111, 222, 333
listen_port = 8765
[db]
path = /var/lib/mnemosyne/mnemosyne.db
[app]
timezone = America/Chicago # inline comment
digest_time = 07:30
END
close $fh;
my $cfg = Mnemosyne::Config->new($tmp);
isa_ok($cfg, 'Mnemosyne::Config');
is($cfg->get('bot', 'token'), 'abc123', 'bot.token');
is($cfg->get('bot', 'listen_port'), '8765', 'bot.listen_port');
is($cfg->get('app', 'digest_time'), '07:30', 'app.digest_time');
is($cfg->get('app', 'timezone'), 'America/Chicago', 'inline comment stripped');
is($cfg->get('db', 'path'), '/var/lib/mnemosyne/mnemosyne.db', 'db.path');
is_deeply($cfg->allowed_chat_ids, [111, 222, 333], 'allowed_chat_ids parsed');
is($cfg->get('bot', 'nonexistent'), undef, 'missing key returns undef');
done_testing;