nginx_upstream_hash-0.3.tar.gz http://wiki.codemongers.com/NginxHttpUpstreamRequestHa...
[nginx.git] / nginx_upstream_hash / t / hashtest.php
1 <?php
2
3 $base_url = "http://localhost:8081/";
4 $failures = 0;
5 $passes = 0;
6
7 function assert_equal($one, $two, $name)
8 {
9     global $failures, $passes;
10     if ($one == $two) {
11         $passes++;
12     } else {
13         echo "Test failed: $name\n";
14         echo "   Expected:  $one\n";
15         echo "   Got:       $two\n";
16         echo "\n";
17         $failures++;
18     }
19 }
20
21 $memcache = new Memcache;
22
23 for ($i=0; $i<20; $i++) {
24     $memcache->addServer("localhost", 11211 + $i);
25 }
26
27 $test_vals = array(
28     'quux' => 'baz',
29     'foo' => 'bar',
30     'shazam' => 'kerpow!',
31     'verbum' => 'word',
32     'felix' => 'happy',
33     'ren' => 'stimpy',
34     'Frank' => 'Julie',
35     'peanuts' => 'cracker jacks',
36     'all-gaul' => 'is divided into three parts',
37     'the-more-tests-the-better' => 'i says',
38     'adsfasw' => 'QA#(@()!@*$$*!!',
39     'Swing-Low' => 'Sweet Cadillac',
40     'can-has-exclamations!' => 'but no spaces or percents',
41     "Smile_if_you_like_UTF-8_\xa6\x3a" => "\xa6\x3b",
42     "8103*$)&^#@*^@!&!)*!_(#" => "whew"
43 );
44
45 $curl = curl_init();
46 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
47
48 foreach ($test_vals as $k => $v ) {
49     assert_equal($memcache->set("/$k", $v), TRUE, "Setting key \"$k\" via PECL");
50     $memcache_url = rawurlencode($k);
51     curl_setopt($curl, CURLOPT_URL, "$base_url$memcache_url");
52     assert_equal($v, curl_exec($curl), "Fetching key \"$k\" via Nginx");
53 }
54
55 curl_close($curl);
56
57 if ($failures > 0) {
58     echo "$passes tests paseed, $failures tests failed\n";
59 } else {
60     echo "All $passes tests passed\n";
61 }