Skip to content

Commit 5424422

Browse files
vgramermjuraga
authored andcommitted
BUG/MINOR: fix GET default sections with full_section=true
the parameter full_section was ignored for /v3/services/haproxy/configuration/defaults endpoint Signed-off-by: Vincent Gramer <vgramer@haproxy.com>
1 parent 72593e2 commit 5424422

File tree

3 files changed

+48
-13
lines changed

3 files changed

+48
-13
lines changed
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
defaults unnamed_defaults_1
2-
mode http
3-
balance roundrobin
4-
timeout client 30000
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 forwardfor except 127.0.0.0/8
18+
option redispatch
19+
retries 3
20+
timeout connect 10s
21+
timeout client 300s
22+
timeout server 300s
23+
maxconn 5000

e2e/tests/defaults/get.bats

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,35 @@ load 'utils/_helpers'
2727
@test "defaults: Return a list of defaults configurations" {
2828
resource_get "$_DEFAULTS_BASE_PATH"
2929
assert_equal "$SC" 200
30-
assert_equal "$(get_json_path "$BODY" '.[0].name')" "unnamed_defaults_1"
30+
31+
# log_target_list is a child resource, it should not be filled when full_section=false
32+
assert_equal "$(get_json_path "$BODY" ".[] | select(.name | contains(\"unnamed_defaults_1\")).log_target_list.[0].global")" "null"
33+
}
34+
35+
@test "default: return a list of defaults configurations with full section" {
36+
resource_get "$_DEFAULTS_BASE_PATH" "full_section=true"
37+
assert_equal "$SC" 200
38+
39+
# log_target_list is a child resource, it should be filled when full_section=true
40+
assert_equal "$(get_json_path "$BODY" ".[] | select(.name | contains(\"unnamed_defaults_1\")).log_target_list.[0].global")" "true"
3141
}
3242

3343
@test "defaults: Return a defaults configuration" {
3444
resource_get "$_DEFAULTS_BASE_PATH/unnamed_defaults_1"
3545
assert_equal "$SC" 200
3646
assert_equal "$(get_json_path "$BODY" '.name')" "unnamed_defaults_1"
47+
48+
# log_target_list is a child resource, it should not be filled when full_section=false
49+
assert_equal "$(get_json_path "$BODY" ".log_target_list.[0].global")" "null"
50+
}
51+
52+
@test "defaults: Return a defaults configuration with full section" {
53+
resource_get "$_DEFAULTS_BASE_PATH/unnamed_defaults_1" "full_section=true"
54+
assert_equal "$SC" 200
55+
assert_equal "$(get_json_path "$BODY" '.name')" "unnamed_defaults_1"
56+
57+
# log_target_list is a child resource, it should be filled when full_section=true
58+
assert_equal "$(get_json_path "$BODY" ".log_target_list.[0].global")" "true"
3759
}
3860

3961
@test "defaults: Return a named defaults configuration that does not exist" {

handlers/defaults.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,15 @@ func (h GetDefaultsSectionsHandlerImpl) Handle(params defaults.GetDefaultsSectio
126126
t = *params.TransactionID
127127
}
128128

129-
configuration, err := h.Client.Configuration()
130-
if err != nil {
131-
e := misc.HandleError(err)
132-
return defaults.NewGetDefaultsSectionsDefault(int(*e.Code)).WithPayload(e)
133-
}
134-
135-
_, fs, err := configuration.GetDefaultsSections(t)
129+
_, fs, err := h.getDefaultsSections(params, t)
136130
if err != nil {
137131
e := misc.HandleError(err)
138132
return defaults.NewGetDefaultsSectionsDefault(int(*e.Code)).WithPayload(e)
139133
}
140134
return defaults.NewGetDefaultsSectionsOK().WithPayload(fs)
141135
}
142136

143-
func (h *GetDefaultsSectionsHandlerImpl) getDefaultsSections(params defaults.GetDefaultsSectionParams, t string) (int64, models.DefaultsSections, error) {
137+
func (h *GetDefaultsSectionsHandlerImpl) getDefaultsSections(params defaults.GetDefaultsSectionsParams, t string) (int64, models.DefaultsSections, error) {
144138
configuration, err := h.Client.Configuration()
145139
if err != nil {
146140
return 0, nil, err

0 commit comments

Comments
 (0)