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 |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 24 | expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv succeeded.*code: 202" |
| 25 | } -start |
| 26 | |
| 27 | haproxy h1 -conf { |
| 28 | defaults |
| 29 | mode http |
Willy Tarreau | f673923 | 2021-11-18 17:46:22 +0100 | [diff] [blame] | 30 | timeout client "${HAPROXY_TEST_TIMEOUT-5s}" |
| 31 | timeout server "${HAPROXY_TEST_TIMEOUT-5s}" |
| 32 | timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" |
Christopher Faulet | 3970819 | 2020-05-05 10:47:36 +0200 | [diff] [blame] | 33 | option log-health-checks |
| 34 | |
| 35 | backend be1 |
| 36 | log ${S1_addr}:${S1_port} len 2048 local0 |
| 37 | option httpchk |
| 38 | http-check expect status 200-399 |
| 39 | |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 40 | http-check expect hdr name "x-test1" |
| 41 | http-check expect hdr name -m str "X-Test2" |
| 42 | http-check expect hdr name -m beg "X-Begin-" |
| 43 | http-check expect hdr name -m end "-End" |
| 44 | http-check expect hdr name -m sub "-Sub-" |
| 45 | 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] | 46 | http-check set-var(check.hdr_name) res.fhdr(x-hdr-name) |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 47 | http-check expect hdr name-lf -m str "%[var(check.hdr_name)]" |
| 48 | 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] | 49 | |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 50 | http-check expect fhdr name "x-test1" value "true, next value" |
| 51 | http-check expect hdr name "x-test2" value -m str "true" |
| 52 | http-check expect hdr name -m beg "x-test" value -m beg "begin-" |
| 53 | http-check expect hdr name -m beg "x-test" value -m end "-end" |
| 54 | http-check expect hdr name -m beg "x-test" value -m sub "-sub-" |
| 55 | http-check expect hdr name -m beg "x-test" value -m reg "^value-reg-[A-Z0-9]+\$" |
| 56 | 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] | 57 | http-check set-var(check.hdr_value) str(x-test1) |
Christopher Faulet | b559426 | 2020-05-05 20:23:13 +0200 | [diff] [blame] | 58 | http-check expect hdr name -m beg "x-" value-lf -m str "%[var(check.hdr_value)]" |
| 59 | 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] | 60 | |
| 61 | server srv ${s1_addr}:${s1_port} check inter 100ms rise 1 fall 1 |
| 62 | } -start |
| 63 | |
| 64 | syslog S1 -wait |