]>
git.proxmox.com Git - pve-manager.git/blob - test/mail_test.pl
6 use Test
::More tests
=> 5;
9 my $STATUS = qr/.*status.*/;
10 my $NO_LOGFILE = qr/.*Could not open log file.*/;
11 my $LOG_TOO_LONG = qr/.*Log output was too long.*/;
12 my $TEST_FILE_PATH = '/tmp/mail_test';
13 my $TEST_FILE_WRONG_PATH = '/tmp/mail_test_wrong';
14 sub prepare_mail_with_status
{
15 open(TEST_FILE
, '>', $TEST_FILE_PATH); # Removes previous content
16 print TEST_FILE
"start of log file\n";
17 print TEST_FILE
"status: 0\% this should not be in the mail\n";
18 print TEST_FILE
"status: 55\% this should not be in the mail\n";
19 print TEST_FILE
"status: 100\% this should not be in the mail\n";
20 print TEST_FILE
"end of log file\n";
23 sub prepare_long_mail
{
24 open(TEST_FILE
, '>', $TEST_FILE_PATH); # Removes previous content
25 # 0.5 MB * 2 parts + the overview tables gives more than 1 MB mail
26 print TEST_FILE
"a" x
(1024*1024/2);
32 my $mock_module = Test
::MockModule-
>new('PVE::Tools');
33 $mock_module->mock('sendmail', sub {
34 my (undef, undef, $text, $html, undef, undef) = @_;
38 my $MAILTO = ['test_address@proxmox.com'];
39 my $OPTS->{mailto
} = $MAILTO;
40 my $SELF->{opts
} = $OPTS;
41 $SELF->{cmdline
} = 'test_command_on_cli';
43 $task->{state} = 'ok';
48 $task->{tmplog
} = $TEST_FILE_WRONG_PATH;
49 my $tasklist = [$task];
50 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
51 like
($result_text, $NO_LOGFILE, "Missing logfile is detected");
56 $task->{tmplog
} = $TEST_FILE_PATH;
57 my $tasklist = [$task];
58 prepare_mail_with_status
();
59 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
60 unlike
($result_text, $STATUS, "Status are not in text part of mails");
61 unlike
($result_html, $STATUS, "Status are not in HTML part of mails");
62 unlink $TEST_FILE_PATH;
67 $task->{tmplog
} = $TEST_FILE_PATH;
68 my $tasklist = [$task];
70 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
71 like
($result_text, $LOG_TOO_LONG, "Text part of mails gets shortened");
72 like
($result_html, $LOG_TOO_LONG, "HTML part of mails gets shortened");
73 unlink $TEST_FILE_PATH;