Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 165 lines (129 sloc) 3.259 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
# vi:filetype=

use lib 'lib';
use Test::Nginx::Socket;

repeat_each(2);

plan tests => repeat_each() * 2 * blocks();

$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;

#no_diff;

run_tests();

__DATA__

=== TEST 1: set exptime
--- config
    location /exptime {
        echo 'flush_all';
        echo_location '/memc?cmd=flush_all';

        echo 'set foo BAR';
        echo_subrequest PUT '/memc?key=foo&exptime=1' -b BAR;

        echo 'get foo - 0 sec';
        echo_location '/memc?key=foo';
        echo;

        echo_blocking_sleep 1.1;

        echo 'get foo - 1.1 sec';
        echo_location '/memc?key=foo';
    }
    location /memc {
        echo_before_body "status: $echo_response_status";
        echo_before_body "exptime: $memc_exptime";

        set $memc_cmd $arg_cmd;
        set $memc_key $arg_key;
        set $memc_exptime $arg_exptime;

        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /exptime
--- response_body_like
^flush_all
status: 200
exptime:
OK\r
set foo BAR
status: 201
exptime: 1
STORED\r
get foo - 0 sec
status: 200
exptime:
BAR
get foo - 1\.1 sec
status: 404
exptime:
<html>.*?404 Not Found.*$



=== TEST 2: test empty flags (default to 0)
--- config
    location /flags {
        echo 'set foo BAR (exptime: EMPTY)';
        echo_subrequest PUT '/memc?key=foo' -b BAR;

        echo_blocking_sleep 1;

        echo 'get foo';
        echo_subrequest GET '/memc?key=foo';
    }

    location /memc {
        echo_before_body "status: $echo_response_status";
        echo_before_body "exptime: $memc_exptime";

        set $memc_key $arg_key;
        set $memc_exptime $arg_exptime;

        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /flags
--- response_body eval
"set foo BAR (exptime: EMPTY)
status: 201
exptime: 0
STORED\r
get foo
status: 200
exptime:
BAR"



=== TEST 3: invalid exptime in set
--- config
    location /allow {
        set $memc_cmd 'set';
        set $memc_key 'foo';
        set $memc_value 'nice';
        set $memc_exptime 'invalid';
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400



=== TEST 4: invalid exptime in flush_all
--- config
    location /allow {
        set $memc_cmd 'flush_all';
        set $memc_key 'foo';
        set $memc_value 'nice';
        set $memc_exptime 'invalid';
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400



=== TEST 5: invalid exptime in delete
--- config
    location /allow {
        set $memc_cmd 'delete';
        set $memc_key 'foo';
        set $memc_value 'nice';
        set $memc_exptime 'invalid';
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400



=== TEST 6: set negative exptime
--- config
    location /allow {
        set $memc_cmd 'set';
        set $memc_key 'sun';
        set $memc_value 'tree';
        set $memc_exptime '-1';
        memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
    }
--- request
    GET /allow
--- response_body_like: 400 Bad Request
--- error_code: 400

Something went wrong with that request. Please try again.