Skip to content

Commit 482bc7d

Browse files
Pratik Mohantymjuraga
Pratik Mohanty
authored andcommitted
MINOR: bind: Add e2e test cases for thread
1 parent 8dc2875 commit 482bc7d

File tree

7 files changed

+106
-19
lines changed

7 files changed

+106
-19
lines changed

e2e/libs/haproxy_config_setup.bash

+14-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,21 @@ setup() {
2929
skip
3030
fi
3131

32+
local haproxy_cfg_file="${BATS_TEST_DIRNAME}/data/haproxy_*.cfg"
33+
local haproxy_file_version=""
34+
35+
if ls $haproxy_cfg_file 1> /dev/null 2>&1; then
36+
haproxy_file_version=$(echo $haproxy_cfg_file | sed 's/.*_\([0-9]\+\.[0-9]\+\)\.cfg/\1/')
37+
fi
38+
39+
major_file_version=$(echo $haproxy_file_version | cut -d '.' -f 1)
40+
minor_file_version=$(echo $haproxy_file_version | cut -d '.' -f 2)
41+
major_cfg_version=$(echo $HAPROXY_VERSION | cut -d '.' -f 1)
42+
minor_cfg_version=$(echo $HAPROXY_VERSION | cut -d '.' -f 2)
43+
3244
# replace the default haproxy config file
33-
if [ $HAPROXY_VERSION = 2.8 ] && [ -f "${BATS_TEST_DIRNAME}/data/haproxy_${HAPROXY_VERSION}.cfg" ]; then
34-
run docker cp "${BATS_TEST_DIRNAME}/data/haproxy_${HAPROXY_VERSION}.cfg" "${DOCKER_CONTAINER_NAME}:/etc/haproxy/haproxy.cfg"
45+
if [[ $major_cfg_version -ge $major_file_version && $minor_cfg_version -ge $minor_file_version ]] && [ -f "${BATS_TEST_DIRNAME}/data/haproxy_${haproxy_file_version}.cfg" ]; then
46+
run docker cp "${BATS_TEST_DIRNAME}/data/haproxy_${haproxy_file_version}.cfg" "${DOCKER_CONTAINER_NAME}:/etc/haproxy/haproxy.cfg"
3547
elif [ -f "${BATS_TEST_DIRNAME}/data/haproxy.cfg" ]; then
3648
run docker cp "${BATS_TEST_DIRNAME}/data/haproxy.cfg" "${DOCKER_CONTAINER_NAME}:/etc/haproxy/haproxy.cfg"
3749
else

e2e/tests/binds/add.bats

+17-4
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,27 @@
1616
#
1717

1818
load '../../libs/dataplaneapi'
19-
load '../../libs/get_json_path'
20-
load '../../libs/haproxy_config_setup'
19+
load "../../libs/get_json_path"
2120
load '../../libs/resource_client'
2221
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
2324

2425
load 'utils/_helpers'
2526

2627
@test "binds: Add a new bind" {
27-
resource_post "$_BIND_BASE_PATH" "data/post.json" "frontend=test_frontend&force_reload=true"
28-
assert_equal "$SC" 201
28+
if haproxy_version_ge "2.5"
29+
then
30+
resource_post "$_BIND_BASE_PATH" "data/post_2.5.json" "frontend=test_frontend&force_reload=true"
31+
else
32+
resource_post "$_BIND_BASE_PATH" "data/post.json" "frontend=test_frontend&force_reload=true"
33+
fi
34+
assert_equal "$SC" 201
35+
if haproxy_version_ge "2.5"
36+
then
37+
resource_get "$_BIND_BASE_PATH/test_bind" "frontend=test_frontend&force_reload=true"
38+
assert_equal "$SC" 200
39+
assert_equal "$(get_json_path "$BODY" '.data.name')" "test_bind"
40+
assert_equal "1/all" "$(get_json_path "$BODY" ".data.thread")"
41+
fi
2942
}

e2e/tests/binds/data/haproxy_2.5.cfg

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
defaults
11+
mode http
12+
maxconn 3000
13+
log global
14+
option httplog
15+
option redispatch
16+
option dontlognull
17+
option http-server-close
18+
option forwardfor except 127.0.0.0/8
19+
timeout http-request 10s
20+
timeout check 10s
21+
timeout connect 10s
22+
timeout client 1m
23+
timeout queue 1m
24+
timeout server 1m
25+
timeout http-keep-alive 10s
26+
retries 3
27+
28+
frontend test_frontend
29+
mode tcp
30+
maxconn 1000
31+
bind localhost:9000 name fixture thread all
32+
bind localhost:9090 name loopback thread 1/1
33+
bind localhost:9091 name loopback1 thread 1/1-1
34+
option httpclose
35+

e2e/tests/binds/data/post_2.5.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"address": "127.0.0.2",
3+
"name": "test_bind",
4+
"port": 10000,
5+
"defer_accept": true,
6+
"allow_0rtt": true,
7+
"thread": "1/all"
8+
}

e2e/tests/binds/delete.bats

+6-5
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
#
1717

1818
load '../../libs/dataplaneapi'
19-
load '../../libs/get_json_path'
20-
load '../../libs/haproxy_config_setup'
19+
load "../../libs/get_json_path"
2120
load '../../libs/resource_client'
2221
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
2324

2425
load 'utils/_helpers'
2526

2627
@test "binds: Delete a bind" {
2728
resource_delete "$_BIND_BASE_PATH/fixture" "frontend=test_frontend&force_reload=true"
28-
assert_equal "$SC" 204
29+
assert_equal "$SC" 204
2930

30-
resource_delete "$_BIND_BASE_PATH/loopback" "frontend=test_frontend&force_reload=true"
31-
assert_equal "$SC" 204
31+
resource_delete "$_BIND_BASE_PATH/loopback" "frontend=test_frontend&force_reload=true"
32+
assert_equal "$SC" 204
3233
}

e2e/tests/binds/get.bats

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@
1616
#
1717

1818
load '../../libs/dataplaneapi'
19-
load '../../libs/get_json_path'
20-
load '../../libs/haproxy_config_setup'
19+
load "../../libs/get_json_path"
2120
load '../../libs/resource_client'
2221
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
2324

2425
load 'utils/_helpers'
2526

2627
@test "binds: Return one bind" {
27-
resource_get "$_BIND_BASE_PATH/fixture" "frontend=test_frontend&force_reload=true"
28-
assert_equal "$SC" 200
28+
resource_get "$_BIND_BASE_PATH/fixture" "frontend=test_frontend&force_reload=true"
29+
assert_equal "$SC" 200
2930
assert_equal "$(get_json_path "$BODY" '.data.name')" "fixture"
31+
if haproxy_version_ge "2.5"
32+
then
33+
assert_equal "all" "$(get_json_path "$BODY" ".data.thread")"
34+
fi
3035
}

e2e/tests/binds/list.bats

+17-4
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,31 @@
1616
#
1717

1818
load '../../libs/dataplaneapi'
19-
load '../../libs/get_json_path'
20-
load '../../libs/haproxy_config_setup'
19+
load "../../libs/get_json_path"
2120
load '../../libs/resource_client'
2221
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
2324

2425
load 'utils/_helpers'
2526

2627
@test "binds: Return an array of binds" {
2728
resource_get "$_BIND_BASE_PATH" "frontend=test_frontend"
28-
assert_equal "$SC" 200
29+
assert_equal "$SC" 200
2930

30-
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
31+
if haproxy_version_ge "2.5"
32+
then
33+
assert_equal 3 "$(get_json_path "$BODY" ".data | length")"
34+
else
35+
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
36+
fi
3137
assert_equal "fixture" "$(get_json_path "$BODY" ".data[0].name")"
3238
assert_equal "loopback" "$(get_json_path "$BODY" ".data[1].name")"
39+
if haproxy_version_ge "2.5"
40+
then
41+
assert_equal "all" "$(get_json_path "$BODY" ".data[0].thread")"
42+
assert_equal "1/1" "$(get_json_path "$BODY" ".data[1].thread")"
43+
assert_equal "loopback1" "$(get_json_path "$BODY" ".data[2].name")"
44+
assert_equal "1/1-1" "$(get_json_path "$BODY" ".data[2].thread")"
45+
fi
3346
}

0 commit comments

Comments
 (0)