]>
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_tools_module = Test
::MockModule-
>new('PVE::Tools');
39 $mock_tools_module->mock('sendmail', sub {
40 my (undef, undef, $text, $html, undef, undef) = @_;
45 my $mock_cluster_module = Test
::MockModule-
>new('PVE::Cluster');
46 $mock_cluster_module->mock('cfs_read_file', sub {
49 if ($path eq 'datacenter.cfg') {
52 die "unexpected cfs_read_file\n";
56 my $MAILTO = ['test_address@proxmox.com'];
58 opts
=> { mailto
=> $MAILTO },
59 cmdline
=> 'test_command_on_cli',
62 my $task = { state => 'ok', vmid
=> '100', };
65 $result_text = $result_html = undef;
66 $task->{tmplog
} = shift;
67 $tasklist = [ $task ];
71 prepare_test
($TEST_FILE_WRONG_PATH);
72 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
73 like
($result_text, $NO_LOGFILE, "Missing logfile is detected");
76 prepare_test
($TEST_FILE_PATH);
77 prepare_mail_with_status
();
78 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
79 unlike
($result_text, $STATUS, "Status are not in text part of mails");
80 unlike
($result_html, $STATUS, "Status are not in HTML part of mails");
83 prepare_test
($TEST_FILE_PATH);
85 PVE
::VZDump
::sendmail
($SELF, $tasklist, 0, undef, undef, undef);
86 like
($result_text, $LOG_TOO_LONG, "Text part of mails gets shortened");
87 like
($result_html, $LOG_TOO_LONG, "HTML part of mails gets shortened");
89 unlink $TEST_FILE_PATH;