comparison smtp.t @ 4:6c41dbb2954f

Tests: run nginx with appropriate config from test itself.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 03 Sep 2008 23:26:29 +0400
parents ce002b2323d3
children 4d75bdb05ecf
comparison
equal deleted inserted replaced
3:ce002b2323d3 4:6c41dbb2954f
7 ############################################################################### 7 ###############################################################################
8 8
9 use warnings; 9 use warnings;
10 use strict; 10 use strict;
11 11
12 use Test::More tests => 26; 12 use Test::More tests => 28;
13 13
14 use File::Temp qw/ tempdir /;
14 use IO::Socket; 15 use IO::Socket;
15 use MIME::Base64; 16 use MIME::Base64;
16 17
17 use constant CRLF => "\x0D\x0A"; 18 use constant CRLF => "\x0D\x0A";
18 19
19 select STDERR; $| = 1; 20 select STDERR; $| = 1;
20 select STDOUT; $| = 1; 21 select STDOUT; $| = 1;
22
23 ###############################################################################
24
25 # Create temp directory and run nginx instance.
26
27 my $tempdir = tempdir('nginx-test-XXXXXXXXXX', TMPDIR => 1, CLEANUP => 1)
28 or die "Can't create temp directory: $!\n";
29
30 my $pid = fork();
31 die "Unable to fork(): $!\n" unless defined $pid;
32
33 if ($pid == 0) {
34 exec('../nginx/objs/nginx', '-c', 'smtp.conf', '-g',
35 "pid $tempdir/nginx.pid; error_log $tempdir/nginx-error.log info;")
36 or die "Unable to exec(): $!\n";
37 print "# child after exec - not reached\n";
38 }
39
40 END {
41 # terminate nginx by SIGTERM
42 kill 15, $pid;
43 wait;
44 }
45
46 # Give nginx some time to start.
47
48 sleep 1;
49
50 ###############################################################################
21 51
22 my $s = smtp_connect(); 52 my $s = smtp_connect();
23 smtp_check(qr/^220 /, "greeting"); 53 smtp_check(qr/^220 /, "greeting");
24 54
25 smtp_send('EHLO example.com'); 55 smtp_send('EHLO example.com');