]>
git.proxmox.com Git - pve-manager.git/blob - test/mail_test.pl
8 use Test
::More tests
=> 5;
13 my $STATUS = qr/.*status.*/;
14 my $NO_LOGFILE = qr/.*Could not open log file.*/;
15 my $LOG_TOO_LONG = qr/.*Log output was too long.*/;
16 my $TEST_FILE_PATH = '/tmp/mail_test';
17 my $TEST_FILE_WRONG_PATH = '/tmp/mail_test_wrong';
19 sub prepare_mail_with_status
{
20 open(TEST_FILE
, '>', $TEST_FILE_PATH); # Removes previous content
21 print TEST_FILE
"start of log file\n";
22 print TEST_FILE
"status: 0\% this should not be in the mail\n";
23 print TEST_FILE
"status: 55\% this should not be in the mail\n";
24 print TEST_FILE
"status: 100\% this should not be in the mail\n";
25 print TEST_FILE
"end of log file\n";
29 sub prepare_long_mail
{
30 open(TEST_FILE
, '>', $TEST_FILE_PATH); # Removes previous content
31 # 0.5 MB * 2 parts + the overview tables gives more than 1 MB mail
32 print TEST_FILE
"a" x
(1024*1024/2);
36 my ($result_text, $result_html);
38 my $mock_module = Test
::MockModule-
>new('PVE::Tools');
39 $mock_module->mock('sendmail', sub {
40 my (undef, undef, $text, $html, undef, undef) = @_;
45 my $MAILTO = ['test_address@proxmox.com'];
47 opts
=> { mailto
=> $MAILTO },
48 cmdline
=> 'test_command_on_cli',
51 my $task = { state => 'ok', vmid
=> '100', };
54 $result_text = $result_html = undef;
55 $task->{tmplog
} = shift;
56 $tasklist = [ $task ];
60 prepare_test
($TEST_FILE_WRONG_PATH);
61 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
62 like
($result_text, $NO_LOGFILE, "Missing logfile is detected");
65 prepare_test
($TEST_FILE_PATH);
66 prepare_mail_with_status
();
67 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
68 unlike
($result_text, $STATUS, "Status are not in text part of mails");
69 unlike
($result_html, $STATUS, "Status are not in HTML part of mails");
72 prepare_test
($TEST_FILE_PATH);
74 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
75 like
($result_text, $LOG_TOO_LONG, "Text part of mails gets shortened");
76 like
($result_html, $LOG_TOO_LONG, "HTML part of mails gets shortened");
78 unlink $TEST_FILE_PATH;