Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 1 | varnishtest "Health-checks: some http-check expect tests" |
| 2 | feature ignore_unknown_macro |
| 3 | #REQUIRE_VERSION=2.2 |
| 4 | #REGTEST_TYPE=slow |
| 5 | # This script tests http-check expect rules. |
| 6 | |
| 7 | server s1 { |
| 8 | rxreq |
| 9 | expect req.method == OPTIONS |
| 10 | expect req.url == / |
| 11 | expect req.proto == HTTP/1.0 |
| 12 | txresp -status 202 \ |
| 13 | -hdr "x-test1: true, next value" \ |
| 14 | -hdr "x-test2: true, begin-value, value-end, value-sub-string, value-reg-123ABC" \ |
| 15 | -hdr "x-begin-test: 1" \ |
| 16 | -hdr "x-test-end: 1" \ |
| 17 | -hdr "x-sub-test: 1" \ |
| 18 | -hdr "x-reg-test1: 1" \ |
| 19 | -hdr "x-hdr-name: x-test1" |
| 20 | } -start |
| 21 | |
| 22 | syslog S1 -level notice { |
| 23 | recv |
| 24 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be1 started." |
| 25 | recv |
| 26 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv succeeded.*code: 202" |
| 27 | } -start |
| 28 | |
| 29 | haproxy h1 -conf { |
| 30 | defaults |
| 31 | mode http |
| 32 | timeout client 1s |
| 33 | timeout server 1s |
| 34 | timeout connect 100ms |
| 35 | option log-health-checks |
| 36 | |
| 37 | backend be1 |
| 38 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 39 | option httpchk |
| 40 | http-check expect status 200-399 |
| 41 | |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 42 | http-check expect hdr name "x-test1" |
| 43 | http-check expect hdr name -m str "X-Test2" |
| 44 | http-check expect hdr name -m beg "X-Begin-" |
| 45 | http-check expect hdr name -m end "-End" |
| 46 | http-check expect hdr name -m sub "-Sub-" |
| 47 | http-check expect hdr name -m reg "^[a-z]+-Reg-[a-z]+[0-9]\$" |
Christopher Faulet | e596d18 | 2020-05-05 17:46:34 +0200 | [diff] [blame] | 48 | http-check set-var(check.hdr_name) res.fhdr(x-hdr-name) |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 49 | http-check expect hdr name-lf -m str "%[var(check.hdr_name)]" |
| 50 | http-check expect hdr name-lf -m str "%[res.fhdr(x-hdr-name)]" |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 51 | |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 52 | http-check expect fhdr name "x-test1" value "true, next value" |
| 53 | http-check expect hdr name "x-test2" value -m str "true" |
| 54 | http-check expect hdr name -m beg "x-test" value -m beg "begin-" |
| 55 | http-check expect hdr name -m beg "x-test" value -m end "-end" |
| 56 | http-check expect hdr name -m beg "x-test" value -m sub "-sub-" |
| 57 | http-check expect hdr name -m beg "x-test" value -m reg "^value-reg-[A-Z0-9]+\$" |
| 58 | http-check expect fhdr name -m beg "x-test" value -m reg "value-reg-[A-Z0-9]+" |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 59 | http-check set-var(check.hdr_value) str(x-test1) |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 60 | http-check expect hdr name -m beg "x-" value-lf -m str "%[var(check.hdr_value)]" |
| 61 | http-check expect fhdr name -m beg "x-" value-lf -m str "%[res.fhdr(x-hdr-name)]" |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 62 | |
| 63 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 64 | } -start |
| 65 | |
| 66 | syslog S1 -wait |