Skip to content

Commit 1af5edb

Browse files
committed
TEST/MEDIUM: defaults: add tests for defaults
1 parent ddad862 commit 1af5edb

File tree

10 files changed

+252
-0
lines changed

10 files changed

+252
-0
lines changed

e2e/tests/defaults/create.bats

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
load '../../libs/debug'
24+
load '../../libs/haproxy_version'
25+
26+
load 'utils/_helpers'
27+
28+
@test "defaults: Create a named defaults configuration" {
29+
resource_post "$_NAMED_DEFAULTS_BASE_PATH" "data/post.json" ""
30+
assert_equal "$SC" 202
31+
32+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/created"
33+
assert_equal "$SC" 200
34+
35+
assert_equal "$(get_json_path "$BODY" '.data.name')" "created"
36+
assert_equal "$(get_json_path "$BODY" '.data.server_timeout')" "20000"
37+
assert_equal "$(get_json_path "$BODY" '.data.client_timeout')" "20000"
38+
assert_equal "$(get_json_path "$BODY" '.data.mode')" "http"
39+
}
40+
41+
@test "defaults: Create a named defaults configuration that already exists" {
42+
resource_post "$_NAMED_DEFAULTS_BASE_PATH" "data/post_existing.json" ""
43+
assert_equal "$SC" 409
44+
}
45+
46+
@test "defaults: Create a named defaults configuration with from" {
47+
haproxy_version_ge $_ERR_SUPPORTED_HAPROXY_VERSION || skip "requires HAProxy $_ERR_SUPPORTED_HAPROXY_VERSION+"
48+
49+
resource_post "$_NAMED_DEFAULTS_BASE_PATH" "data/post.json" ""
50+
assert_equal "$SC" 202
51+
52+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/created"
53+
assert_equal "$SC" 200
54+
55+
resource_post "$_NAMED_DEFAULTS_BASE_PATH" "data/post_with_from.json" ""
56+
assert_equal "$SC" 202
57+
58+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/created_with_from"
59+
assert_equal "$SC" 200
60+
61+
assert_equal "$(get_json_path "$BODY" '.data.name')" "created_with_from"
62+
assert_equal "$(get_json_path "$BODY" '.data.from')" "created"
63+
assert_equal "$(get_json_path "$BODY" '.data.server_timeout')" "20000"
64+
assert_equal "$(get_json_path "$BODY" '.data.client_timeout')" "20000"
65+
assert_equal "$(get_json_path "$BODY" '.data.mode')" "http"
66+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
defaults
2+
mode http
3+
balance roundrobin
4+
timeout client 30000

e2e/tests/defaults/data/post.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "created",
3+
"client_timeout": 20000,
4+
"server_timeout": 20000,
5+
"mode": "http"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "unnamed_defaults_1",
3+
"client_timeout": 20000,
4+
"server_timeout": 20000,
5+
"mode": "http"
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "created_with_from",
3+
"from": "created",
4+
"client_timeout": 20000,
5+
"server_timeout": 20000,
6+
"mode": "http"
7+
}

e2e/tests/defaults/data/put.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"client_timeout": 25000,
3+
"server_timeout": 25000,
4+
"mode": "tcp"
5+
}

e2e/tests/defaults/delete.bats

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 "defaults: Delete a named defaults configuration" {
27+
resource_delete "$_NAMED_DEFAULTS_BASE_PATH/unnamed_defaults_1"
28+
assert_equal "$SC" 202
29+
}
30+
31+
@test "defaults: Delete a named defaults configuration that does not exist" {
32+
resource_delete "$_NAMED_DEFAULTS_BASE_PATH/nothing_to_see_here"
33+
assert_equal "$SC" 404
34+
}

e2e/tests/defaults/get.bats

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 "defaults: Return a defaults configuration" {
27+
resource_get "$_DEFAULTS_BASE_PATH"
28+
assert_equal "$SC" 200
29+
assert_equal "$(get_json_path "$BODY" '.data.mode')" "http"
30+
assert_equal "$(get_json_path "$BODY" '.data.balance.algorithm')" "roundrobin"
31+
assert_equal "$(get_json_path "$BODY" '.data.client_timeout')" "30000"
32+
}
33+
34+
@test "defaults: Return a list of named defaults configurations" {
35+
resource_get "$_NAMED_DEFAULTS_BASE_PATH"
36+
assert_equal "$SC" 200
37+
assert_equal "$(get_json_path "$BODY" '.data[0].name')" "unnamed_defaults_1"
38+
}
39+
40+
@test "defaults: Return a named defaults configuration" {
41+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/unnamed_defaults_1"
42+
assert_equal "$SC" 200
43+
assert_equal "$(get_json_path "$BODY" '.data.name')" "unnamed_defaults_1"
44+
}
45+
46+
@test "defaults: Return a named defaults configuration that does not exist" {
47+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/nothing_to_see_here"
48+
assert_equal "$SC" 404
49+
}

e2e/tests/defaults/replace.bats

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 "defaults: Replace a defaults configuration" {
27+
resource_put "$_DEFAULTS_BASE_PATH" "data/put.json" ""
28+
assert_equal "$SC" 202
29+
30+
resource_get "$_DEFAULTS_BASE_PATH" ""
31+
assert_equal "$SC" 200
32+
33+
assert_equal "$(get_json_path "$BODY" '.data.server_timeout')" "25000"
34+
assert_equal "$(get_json_path "$BODY" '.data.client_timeout')" "25000"
35+
assert_equal "$(get_json_path "$BODY" '.data.mode')" "tcp"
36+
}
37+
38+
@test "defaults: Replace a named defaults configuration" {
39+
resource_put "$_NAMED_DEFAULTS_BASE_PATH/unnamed_defaults_1" "data/put.json" ""
40+
assert_equal "$SC" 202
41+
42+
resource_get "$_NAMED_DEFAULTS_BASE_PATH/unnamed_defaults_1"
43+
assert_equal "$SC" 200
44+
45+
assert_equal "$(get_json_path "$BODY" '.data.name')" "unnamed_defaults_1"
46+
assert_equal "$(get_json_path "$BODY" '.data.server_timeout')" "25000"
47+
assert_equal "$(get_json_path "$BODY" '.data.client_timeout')" "25000"
48+
assert_equal "$(get_json_path "$BODY" '.data.mode')" "tcp"
49+
}
50+
51+
@test "defaults: Replace a named defaults configuration that does not exist" {
52+
resource_put "$_NAMED_DEFAULTS_BASE_PATH/nothing_to_see_here" "data/put.json" ""
53+
assert_equal "$SC" 404
54+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
_DEFAULTS_BASE_PATH="/services/haproxy/configuration/defaults"
19+
20+
_NAMED_DEFAULTS_BASE_PATH="/services/haproxy/configuration/named_defaults"
21+
_ERR_SUPPORTED_HAPROXY_VERSION="2.4"

0 commit comments

Comments
 (0)