Skip to content

Commit 7ba2269

Browse files
vgramerGopher Bot
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 cdc5102 commit 7ba2269

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

e2e/tests/defaults/data/haproxy.cfg

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,15 @@ global
99
group haproxy
1010
stats socket /var/lib/haproxy/stats level admin
1111

12-
defaults mydefaults
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-
defaults unnamed_defaults_1
31-
mode http
32-
balance roundrobin
33-
timeout client 30000
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +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+
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"
3041
}
3142

3243
@test "defaults: Return a defaults configuration" {
3344
resource_get "$_DEFAULTS_BASE_PATH/unnamed_defaults_1"
3445
assert_equal "$SC" 200
3546
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"
3659
}
3760

3861
@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)