Skip to content

Commit a4d46f5

Browse files
committed
TEST/MINOR: log_targets: add tests for this endpoint
1 parent bcd4bd5 commit a4d46f5

File tree

11 files changed

+576
-0
lines changed

11 files changed

+576
-0
lines changed

e2e/tests/log_targets/accept.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"nolog": true,
3+
"index": 0
4+
}

e2e/tests/log_targets/add.bats

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2019 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/version'
20+
21+
setup() {
22+
run dpa_curl POST "/services/haproxy/configuration/frontends?force_reload=true&version=$(version)" "/frontends_post.json"
23+
assert_success
24+
25+
dpa_curl_status_body '$output'
26+
assert_equal $SC 201
27+
run dpa_curl POST "/services/haproxy/configuration/backends?force_reload=true&version=$(version)" "/backends_post.json"
28+
assert_success
29+
30+
dpa_curl_status_body '$output'
31+
assert_equal $SC 201
32+
}
33+
34+
teardown() {
35+
run dpa_curl DELETE "/services/haproxy/configuration/frontends/test_frontend?force_reload=true&version=$(version)"
36+
assert_success
37+
38+
dpa_curl_status_body '$output'
39+
assert_equal $SC 204
40+
run dpa_curl DELETE "/services/haproxy/configuration/backends/test_backend?force_reload=true&version=$(version)"
41+
assert_success
42+
43+
dpa_curl_status_body '$output'
44+
assert_equal $SC 204
45+
}
46+
47+
@test "log_targets: Add a new Log Target to frontend" {
48+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=frontend&parent_name=test_frontend&force_reload=true&version=$(version)" "../log_targets/accept.json"
49+
assert_success
50+
51+
dpa_curl_status_body '$output'
52+
assert_equal $SC 201
53+
}
54+
55+
@test "log_targets: Add a new Log Target to backend" {
56+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=backend&parent_name=test_backend&force_reload=true&version=$(version)" "../log_targets/accept.json"
57+
assert_success
58+
59+
dpa_curl_status_body '$output'
60+
assert_equal $SC 201
61+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"balance": {
3+
"algorithm": "roundrobin"
4+
},
5+
"forwardfor": {
6+
"enabled": "enabled"
7+
},
8+
"httpchk": {
9+
"method": "GET",
10+
"uri": "/check",
11+
"version": "HTTP/1.1"
12+
},
13+
"mode": "http",
14+
"name": "test_backend"
15+
}

e2e/tests/log_targets/delete.bats

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2019 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/version'
20+
21+
setup() {
22+
# creating frontend and related Log Target
23+
run dpa_curl POST "/services/haproxy/configuration/frontends?force_reload=true&version=$(version)" "/frontends_post.json"
24+
assert_success
25+
26+
dpa_curl_status_body '$output'
27+
assert_equal $SC 201
28+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=frontend&parent_name=test_frontend&force_reload=true&version=$(version)" "../log_targets/accept.json"
29+
assert_success
30+
31+
dpa_curl_status_body '$output'
32+
assert_equal $SC 201
33+
# creating backend and related Log target
34+
run dpa_curl POST "/services/haproxy/configuration/backends?force_reload=true&version=$(version)" "/backends_post.json"
35+
assert_success
36+
37+
dpa_curl_status_body '$output'
38+
assert_equal $SC 201
39+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=backend&parent_name=test_backend&force_reload=true&version=$(version)" "../log_targets/accept.json"
40+
assert_success
41+
42+
dpa_curl_status_body '$output'
43+
assert_equal $SC 201
44+
}
45+
46+
teardown() {
47+
run dpa_curl DELETE "/services/haproxy/configuration/frontends/test_frontend?force_reload=true&version=$(version)"
48+
assert_success
49+
50+
dpa_curl_status_body '$output'
51+
assert_equal $SC 204
52+
run dpa_curl DELETE "/services/haproxy/configuration/backends/test_backend?force_reload=true&version=$(version)"
53+
assert_success
54+
55+
dpa_curl_status_body '$output'
56+
assert_equal $SC 204
57+
}
58+
59+
@test "log_targets: Delete a Log Target from frontend" {
60+
run dpa_curl DELETE "/services/haproxy/configuration/log_targets/0?parent_type=frontend&parent_name=test_frontend&force_reload=true&version=$(version)"
61+
assert_success
62+
63+
dpa_curl_status_body '$output'
64+
assert_equal $SC 204
65+
}
66+
67+
@test "log_targets: Delete a Log Target from backend" {
68+
run dpa_curl DELETE "/services/haproxy/configuration/log_targets/0?parent_type=backend&parent_name=test_backend&force_reload=true&version=$(version)"
69+
assert_success
70+
71+
dpa_curl_status_body '$output'
72+
assert_equal $SC 204
73+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"http_connection_mode": "httpclose",
3+
"maxconn": 1000,
4+
"mode": "tcp",
5+
"name": "test_frontend"
6+
}

e2e/tests/log_targets/get.bats

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2019 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/version'
21+
22+
setup() {
23+
# creating frontend and related Log Target
24+
run dpa_curl POST "/services/haproxy/configuration/frontends?force_reload=true&version=$(version)" "/frontends_post.json"
25+
assert_success
26+
27+
dpa_curl_status_body '$output'
28+
assert_equal $SC 201
29+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=frontend&parent_name=test_frontend&force_reload=true&version=$(version)" "../log_targets/accept.json"
30+
assert_success
31+
32+
dpa_curl_status_body '$output'
33+
assert_equal $SC 201
34+
# creating backend and related Log Target
35+
run dpa_curl POST "/services/haproxy/configuration/backends?force_reload=true&version=$(version)" "/backends_post.json"
36+
assert_success
37+
38+
dpa_curl_status_body '$output'
39+
assert_equal $SC 201
40+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=backend&parent_name=test_backend&force_reload=true&version=$(version)" "../log_targets/accept.json"
41+
assert_success
42+
43+
dpa_curl_status_body '$output'
44+
assert_equal $SC 201
45+
46+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=global&force_reload=true&version=$(version)" "../log_targets/accept.json"
47+
assert_success
48+
49+
dpa_curl_status_body '$output'
50+
assert_equal $SC 201
51+
52+
run dpa_curl POST "/services/haproxy/configuration/log_targets?parent_type=defaults&force_reload=true&version=$(version)" "../log_targets/accept.json"
53+
assert_success
54+
55+
dpa_curl_status_body '$output'
56+
assert_equal $SC 201
57+
}
58+
59+
teardown() {
60+
run dpa_curl DELETE "/services/haproxy/configuration/frontends/test_frontend?force_reload=true&version=$(version)"
61+
assert_success
62+
63+
dpa_curl_status_body '$output'
64+
assert_equal $SC 204
65+
run dpa_curl DELETE "/services/haproxy/configuration/backends/test_backend?force_reload=true&version=$(version)"
66+
assert_success
67+
68+
dpa_curl_status_body '$output'
69+
assert_equal $SC 204
70+
71+
run dpa_curl DELETE "/services/haproxy/configuration/log_targets/0?parent_type=global&force_reload=true&version=$(version)"
72+
assert_success
73+
74+
dpa_curl_status_body '$output'
75+
assert_equal $SC 204
76+
77+
run dpa_curl DELETE "/services/haproxy/configuration/log_targets/0?parent_type=defaults&force_reload=true&version=$(version)"
78+
assert_success
79+
80+
dpa_curl_status_body '$output'
81+
assert_equal $SC 204
82+
}
83+
84+
@test "log_targets: Return one Log Target from frontend" {
85+
run dpa_curl GET "/services/haproxy/configuration/log_targets/0?parent_type=frontend&parent_name=test_frontend"
86+
assert_success
87+
88+
dpa_curl_status_body '$output'
89+
assert_equal $SC 200
90+
[ "$(get_json_path "${BODY}" ".data.nolog")" = true ]
91+
}
92+
93+
@test "log_targets: Return one Log Target from backend" {
94+
run dpa_curl GET "/services/haproxy/configuration/log_targets/0?parent_type=backend&parent_name=test_backend"
95+
assert_success
96+
97+
dpa_curl_status_body '$output'
98+
assert_equal $SC 200
99+
[ "$(get_json_path "${BODY}" ".data.nolog")" = true ]
100+
}
101+
102+
@test "log_targets: Return one Log Target from global" {
103+
run dpa_curl GET "/services/haproxy/configuration/log_targets/0?parent_type=global"
104+
assert_success
105+
106+
dpa_curl_status_body '$output'
107+
assert_equal $SC 200
108+
[ "$(get_json_path "${BODY}" ".data.nolog")" = true ]
109+
}
110+
111+
@test "log_targets: Return one Log Target from defaults" {
112+
run dpa_curl GET "/services/haproxy/configuration/log_targets/0?parent_type=defaults"
113+
assert_success
114+
115+
dpa_curl_status_body '$output'
116+
assert_equal $SC 200
117+
[ "$(get_json_path "${BODY}" ".data.nolog")" = true ]
118+
}

e2e/tests/log_targets/global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"address": "localhost",
3+
"format": "raw",
4+
"facility": "user",
5+
"level": "warning",
6+
"index": 1
7+
}

0 commit comments

Comments
 (0)