comparison memcached.t @ 29:71ea39729fa0

Tests: memcached module generic tests. This also includes relevant framework improvements, notably the ability to test presence of external daemons and to run them.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 11 Oct 2008 10:58:43 +0400
parents
children 689174c36e94
comparison
equal deleted inserted replaced
28:8f1519472ece 29:71ea39729fa0
1 #!/usr/bin/perl
2
3 # (C) Maxim Dounin
4
5 # Test for memcached backend.
6
7 ###############################################################################
8
9 use warnings;
10 use strict;
11
12 use Test::More;
13
14 use IO::Select;
15
16 BEGIN { use FindBin; chdir($FindBin::Bin); }
17
18 use lib 'lib';
19 use Test::Nginx;
20
21 ###############################################################################
22
23 select STDERR; $| = 1;
24 select STDOUT; $| = 1;
25
26 eval { require Cache::Memcached; };
27 plain(skip_all => 'Cache::Memcached not installed') if $@;
28
29 my $t = Test::Nginx->new()->has('rewrite')->has_daemon('memcached')->plan(2)
30 ->write_file_expand('nginx.conf', <<'EOF');
31
32 master_process off;
33 daemon off;
34
35 events {
36 worker_connections 1024;
37 }
38
39 http {
40 access_log off;
41
42 server {
43 listen localhost:8080;
44 server_name localhost;
45
46 location / {
47 set $memcached_key $uri;
48 memcached_pass 127.0.0.1:8081;
49 }
50 }
51 }
52
53 EOF
54
55 $t->run_daemon('memcached', '-l', '127.0.0.1', '-p', '8081');
56 $t->run();
57
58 ###############################################################################
59
60 my $memd = Cache::Memcached->new(servers => [ '127.0.0.1:8081' ]);
61 $memd->set('/', 'SEE-THIS');
62
63 like(http_get('/'), qr/SEE-THIS/, 'memcached request');
64 like(http_get('/notfound'), qr/404/, 'memcached not found');
65
66 ###############################################################################