Skip to content

Commit 279c1ca

Browse files
committed
TEST/MINOR: cache: add cache e2e tests
1 parent 1bdfa23 commit 279c1ca

File tree

10 files changed

+283
-0
lines changed

10 files changed

+283
-0
lines changed

e2e/tests/cache/create.bats

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "cache: Create one new cache" {
27+
resource_post "$_CACHE_BASE_PATH" "data/cache.json" "force_reload=true"
28+
assert_equal "$SC" 201
29+
30+
resource_get "$_CACHE_BASE_PATH/cache_created"
31+
assert_equal "$SC" 200
32+
assert_equal "cache_created" "$(get_json_path "$BODY" ".data.name")"
33+
assert_equal 1 "$(get_json_path "$BODY" ".data.max_object_size")"
34+
assert_equal 1000 "$(get_json_path "$BODY" ".data.total_max_size")"
35+
}
36+
37+
38+
@test "cache: Fail creating cache with same name" {
39+
resource_post "$_CACHE_BASE_PATH" "data/cache_same_name.json" "force_reload=true"
40+
assert_equal "$SC" 409
41+
}
42+
43+
@test "cache: Fail creating cache that isn't valid" {
44+
resource_post "$_CACHE_BASE_PATH" "data/cache_unvalid.json" "force_reload=true"
45+
assert_equal "$SC" 400
46+
}

e2e/tests/cache/data/cache.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "cache_created",
3+
"max_object_size": 1,
4+
"total_max_size": 1000
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "test_cache",
3+
"max_object_size": 1,
4+
"total_max_size": 1000
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "cache_created",
3+
"max_object_size": "1",
4+
"test": 1000
5+
}

e2e/tests/cache/data/haproxy.cfg

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# _version=42
2+
3+
global
4+
log 127.0.0.1 local2
5+
chroot /var/lib/haproxy
6+
pidfile /var/run/haproxy.pid
7+
maxconn 4000
8+
user haproxy
9+
group haproxy
10+
stats socket /var/lib/haproxy/stats level admin
11+
12+
defaults
13+
mode http
14+
log global
15+
option httplog
16+
option dontlognull
17+
option http-server-close
18+
option forwardfor except 127.0.0.0/8
19+
option redispatch
20+
retries 3
21+
timeout http-request 10s
22+
timeout queue 1m
23+
timeout connect 10s
24+
timeout client 1m
25+
timeout server 1m
26+
timeout http-keep-alive 10s
27+
timeout check 10s
28+
maxconn 3000
29+
30+
cache test_cache
31+
total-max-size 1024
32+
max-object-size 8
33+
max-age 60
34+
35+
cache test_cache2
36+
total-max-size 1024

e2e/tests/cache/delete.bats

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "cache: Delete one cache by name" {
27+
resource_delete "$_CACHE_BASE_PATH/test_cache2" "force_reload=true"
28+
assert_equal "$SC" 204
29+
30+
resource_get "$_CACHE_BASE_PATH/test_cache2"
31+
assert_equal "$SC" 404
32+
}
33+
34+
35+
@test "cache: Fail deleting cache that doesn't exist" {
36+
resource_delete "$_CACHE_BASE_PATH/i_am_not_here" "force_reload=true"
37+
assert_equal "$SC" 404
38+
}

e2e/tests/cache/get.bats

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "cache: Return one cache by name" {
27+
resource_get "$_CACHE_BASE_PATH/test_cache"
28+
assert_equal "$SC" 200
29+
assert_equal "test_cache" "$(get_json_path "$BODY" ".data.name")"
30+
assert_equal 60 "$(get_json_path "$BODY" ".data.max_age")"
31+
assert_equal 8 "$(get_json_path "$BODY" ".data.max_object_size")"
32+
assert_equal 1024 "$(get_json_path "$BODY" ".data.total_max_size")"
33+
}
34+
35+
36+
@test "cache: Fail returning cache that doesn't exist" {
37+
resource_get "$_CACHE_BASE_PATH/i_am_not_here"
38+
assert_equal "$SC" 404
39+
}

e2e/tests/cache/list.bats

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "cache: Return an array of caches" {
27+
resource_get "$_CACHE_BASE_PATH"
28+
assert_equal "$SC" 200
29+
assert_equal 2 "$(get_json_path "$BODY" ".data | length")"
30+
31+
for (( i=0; i<=1; i++ ))
32+
do
33+
if [ "$(get_json_path "$BODY" ".data[$i].name")" == "test_cache" ]
34+
then
35+
assert_equal 60 "$(get_json_path "$BODY" ".data[$i].max_age")"
36+
assert_equal 8 "$(get_json_path "$BODY" ".data[$i].max_object_size")"
37+
assert_equal 1024 "$(get_json_path "$BODY" ".data[$i].total_max_size")"
38+
elif [ "$(get_json_path "$BODY" ".data[$i].name")" == "test_cache2" ]
39+
then
40+
assert_equal 1024 "$(get_json_path "$BODY" ".data[$i].total_max_size")"
41+
else
42+
assert_failure
43+
fi
44+
done
45+
}

e2e/tests/cache/replace.bats

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load '../../libs/get_json_path'
20+
load '../../libs/haproxy_config_setup'
21+
load '../../libs/resource_client'
22+
load '../../libs/version'
23+
24+
load 'utils/_helpers'
25+
26+
@test "cache: Replace one cache" {
27+
resource_put "$_CACHE_BASE_PATH/test_cache" "data/cache_same_name.json" "force_reload=true"
28+
assert_equal "$SC" 200
29+
30+
resource_get "$_CACHE_BASE_PATH/test_cache"
31+
assert_equal "$SC" 200
32+
assert_equal "test_cache" "$(get_json_path "$BODY" ".data.name")"
33+
assert_equal 1 "$(get_json_path "$BODY" ".data.max_object_size")"
34+
assert_equal 1000 "$(get_json_path "$BODY" ".data.total_max_size")"
35+
}
36+
37+
38+
@test "cache: Fail replacing cache that doesn't exist" {
39+
resource_put "$_CACHE_BASE_PATH/i_am_not_here" "data/cache_same_name.json" "force_reload=true"
40+
assert_equal "$SC" 404
41+
}
42+
43+
@test "cache: Fail creating cache that isn't valid" {
44+
resource_put "$_CACHE_BASE_PATH/test_cache" "data/cache_unvalid.json" "force_reload=true"
45+
assert_equal "$SC" 400
46+
}

e2e/tests/cache/utils/_helpers.bash

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2022 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
_CACHE_BASE_PATH="/services/haproxy/configuration/caches"

0 commit comments

Comments
 (0)