Skip to content

Commit 01a66ee

Browse files
hbagdiTravis Raines
authored and
Travis Raines
committed
fix: remove defaults for values which can be set to 0 or false
This is an issue due to the underlying library (mergo). For existing installations which are relying on defaulting behavior of decK, this will cause false positives in diffs. This is not considered a breaking change and hopefully will be only a small inconvenience to users. Fix #134
1 parent c8589f4 commit 01a66ee

File tree

3 files changed

+144
-34
lines changed

3 files changed

+144
-34
lines changed

file/builder_test.go

+15-24
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ func Test_stateBuilder_services(t *testing.T) {
299299
ID: kong.String("4bfcb11f-c962-4817-83e5-9433cf20b663"),
300300
Name: kong.String("foo"),
301301
Port: kong.Int(80),
302-
Retries: kong.Int(5),
303302
Protocol: kong.String("http"),
304303
ConnectTimeout: kong.Int(60000),
305304
WriteTimeout: kong.Int(60000),
@@ -329,7 +328,6 @@ func Test_stateBuilder_services(t *testing.T) {
329328
ID: kong.String("538c7f96-b164-4f1b-97bb-9f4bb472e89f"),
330329
Name: kong.String("foo"),
331330
Port: kong.Int(80),
332-
Retries: kong.Int(5),
333331
Protocol: kong.String("http"),
334332
ConnectTimeout: kong.Int(60000),
335333
WriteTimeout: kong.Int(60000),
@@ -1456,10 +1454,9 @@ func Test_stateBuilder_upstream(t *testing.T) {
14561454
Interval: kong.Int(0),
14571455
Successes: kong.Int(0),
14581456
},
1459-
HTTPPath: kong.String("/"),
1460-
HTTPSVerifyCertificate: kong.Bool(true),
1461-
Type: kong.String("http"),
1462-
Timeout: kong.Int(1),
1457+
HTTPPath: kong.String("/"),
1458+
Type: kong.String("http"),
1459+
Timeout: kong.Int(1),
14631460
Unhealthy: &kong.Unhealthy{
14641461
HTTPFailures: kong.Int(0),
14651462
TCPFailures: kong.Int(0),
@@ -1519,10 +1516,9 @@ func Test_stateBuilder_upstream(t *testing.T) {
15191516
Interval: kong.Int(0),
15201517
Successes: kong.Int(0),
15211518
},
1522-
HTTPPath: kong.String("/"),
1523-
HTTPSVerifyCertificate: kong.Bool(true),
1524-
Type: kong.String("http"),
1525-
Timeout: kong.Int(1),
1519+
HTTPPath: kong.String("/"),
1520+
Type: kong.String("http"),
1521+
Timeout: kong.Int(1),
15261522
Unhealthy: &kong.Unhealthy{
15271523
HTTPFailures: kong.Int(0),
15281524
TCPFailures: kong.Int(0),
@@ -1586,10 +1582,9 @@ func Test_stateBuilder_upstream(t *testing.T) {
15861582
Interval: kong.Int(0),
15871583
Successes: kong.Int(0),
15881584
},
1589-
HTTPPath: kong.String("/"),
1590-
HTTPSVerifyCertificate: kong.Bool(true),
1591-
Type: kong.String("http"),
1592-
Timeout: kong.Int(1),
1585+
HTTPPath: kong.String("/"),
1586+
Type: kong.String("http"),
1587+
Timeout: kong.Int(1),
15931588
Unhealthy: &kong.Unhealthy{
15941589
HTTPFailures: kong.Int(0),
15951590
TCPFailures: kong.Int(0),
@@ -1629,10 +1624,9 @@ func Test_stateBuilder_upstream(t *testing.T) {
16291624
Interval: kong.Int(0),
16301625
Successes: kong.Int(0),
16311626
},
1632-
HTTPPath: kong.String("/"),
1633-
HTTPSVerifyCertificate: kong.Bool(true),
1634-
Type: kong.String("http"),
1635-
Timeout: kong.Int(1),
1627+
HTTPPath: kong.String("/"),
1628+
Type: kong.String("http"),
1629+
Timeout: kong.Int(1),
16361630
Unhealthy: &kong.Unhealthy{
16371631
HTTPFailures: kong.Int(0),
16381632
TCPFailures: kong.Int(0),
@@ -1751,7 +1745,6 @@ func Test_stateBuilder(t *testing.T) {
17511745
ID: kong.String("538c7f96-b164-4f1b-97bb-9f4bb472e89f"),
17521746
Name: kong.String("foo-service"),
17531747
Port: kong.Int(80),
1754-
Retries: kong.Int(5),
17551748
Protocol: kong.String("http"),
17561749
ConnectTimeout: kong.Int(60000),
17571750
WriteTimeout: kong.Int(60000),
@@ -1762,7 +1755,6 @@ func Test_stateBuilder(t *testing.T) {
17621755
ID: kong.String("dfd79b4d-7642-4b61-ba0c-9f9f0d3ba55b"),
17631756
Name: kong.String("bar-service"),
17641757
Port: kong.Int(80),
1765-
Retries: kong.Int(5),
17661758
Protocol: kong.String("http"),
17671759
ConnectTimeout: kong.Int(60000),
17681760
WriteTimeout: kong.Int(60000),
@@ -1833,10 +1825,9 @@ func Test_stateBuilder(t *testing.T) {
18331825
Interval: kong.Int(0),
18341826
Successes: kong.Int(0),
18351827
},
1836-
HTTPPath: kong.String("/"),
1837-
HTTPSVerifyCertificate: kong.Bool(true),
1838-
Type: kong.String("http"),
1839-
Timeout: kong.Int(1),
1828+
HTTPPath: kong.String("/"),
1829+
Type: kong.String("http"),
1830+
Timeout: kong.Int(1),
18401831
Unhealthy: &kong.Unhealthy{
18411832
HTTPFailures: kong.Int(0),
18421833
TCPFailures: kong.Int(0),

utils/constants.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import "github.com/hbagdi/go-kong/kong"
55
var (
66
serviceDefaults = kong.Service{
77
Port: kong.Int(80),
8-
Retries: kong.Int(5),
98
Protocol: kong.String("http"),
109
ConnectTimeout: kong.Int(60000),
1110
WriteTimeout: kong.Int(60000),
@@ -30,10 +29,9 @@ var (
3029
Interval: kong.Int(0),
3130
Successes: kong.Int(0),
3231
},
33-
HTTPPath: kong.String("/"),
34-
HTTPSVerifyCertificate: kong.Bool(true),
35-
Type: kong.String("http"),
36-
Timeout: kong.Int(1),
32+
HTTPPath: kong.String("/"),
33+
Type: kong.String("http"),
34+
Timeout: kong.Int(1),
3735
Unhealthy: &kong.Unhealthy{
3836
HTTPFailures: kong.Int(0),
3937
TCPFailures: kong.Int(0),

utils/defaulter_test.go

+126-5
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,27 @@ func TestServiceSetTest(t *testing.T) {
6868
arg: &kong.Service{},
6969
want: &serviceDefaults,
7070
},
71+
{
72+
desc: "retries can be set to 0",
73+
arg: &kong.Service{
74+
Retries: kong.Int(0),
75+
},
76+
want: &kong.Service{
77+
Port: kong.Int(80),
78+
Retries: kong.Int(0),
79+
Protocol: kong.String("http"),
80+
ConnectTimeout: kong.Int(60000),
81+
WriteTimeout: kong.Int(60000),
82+
ReadTimeout: kong.Int(60000),
83+
},
84+
},
7185
{
7286
desc: "timeout value value is not overridden",
7387
arg: &kong.Service{
7488
WriteTimeout: kong.Int(42),
7589
},
7690
want: &kong.Service{
7791
Port: kong.Int(80),
78-
Retries: kong.Int(5),
7992
Protocol: kong.String("http"),
8093
ConnectTimeout: kong.Int(60000),
8194
WriteTimeout: kong.Int(42),
@@ -89,7 +102,6 @@ func TestServiceSetTest(t *testing.T) {
89102
},
90103
want: &kong.Service{
91104
Port: kong.Int(80),
92-
Retries: kong.Int(5),
93105
Protocol: kong.String("http"),
94106
Path: kong.String("/foo"),
95107
ConnectTimeout: kong.Int(60000),
@@ -108,7 +120,6 @@ func TestServiceSetTest(t *testing.T) {
108120
Name: kong.String("foo"),
109121
Host: kong.String("example.com"),
110122
Port: kong.Int(80),
111-
Retries: kong.Int(5),
112123
Protocol: kong.String("http"),
113124
Path: kong.String("/bar"),
114125
ConnectTimeout: kong.Int(60000),
@@ -255,8 +266,117 @@ func TestUpstreamSetTest(t *testing.T) {
255266
Interval: kong.Int(0),
256267
Successes: kong.Int(0),
257268
},
269+
HTTPPath: kong.String("/"),
270+
Type: kong.String("http"),
271+
Timeout: kong.Int(1),
272+
Unhealthy: &kong.Unhealthy{
273+
HTTPFailures: kong.Int(0),
274+
TCPFailures: kong.Int(0),
275+
Timeouts: kong.Int(0),
276+
HTTPStatuses: []int{429, 404, 500, 501, 502, 503, 504, 505},
277+
Interval: kong.Int(0),
278+
},
279+
},
280+
Passive: &kong.PassiveHealthcheck{
281+
Healthy: &kong.Healthy{
282+
HTTPStatuses: []int{200, 201, 202, 203, 204, 205,
283+
206, 207, 208, 226, 300, 301, 302, 303, 304, 305,
284+
306, 307, 308},
285+
Successes: kong.Int(0),
286+
},
287+
Unhealthy: &kong.Unhealthy{
288+
HTTPFailures: kong.Int(0),
289+
TCPFailures: kong.Int(0),
290+
Timeouts: kong.Int(0),
291+
HTTPStatuses: []int{429, 500, 503},
292+
},
293+
},
294+
},
295+
HashOn: kong.String("none"),
296+
HashFallback: kong.String("none"),
297+
HashOnCookiePath: kong.String("/"),
298+
},
299+
},
300+
{
301+
desc: "Healthchecks.Active.Healthy.Timeout is not overridden",
302+
arg: &kong.Upstream{
303+
Name: kong.String("foo"),
304+
Healthchecks: &kong.Healthcheck{
305+
Active: &kong.ActiveHealthcheck{
306+
Healthy: &kong.Healthy{
307+
Interval: kong.Int(1),
308+
},
309+
},
310+
},
311+
},
312+
want: &kong.Upstream{
313+
Name: kong.String("foo"),
314+
Slots: kong.Int(10000),
315+
Healthchecks: &kong.Healthcheck{
316+
Active: &kong.ActiveHealthcheck{
317+
Concurrency: kong.Int(10),
318+
Healthy: &kong.Healthy{
319+
HTTPStatuses: []int{200, 302},
320+
Interval: kong.Int(1),
321+
Successes: kong.Int(0),
322+
},
323+
HTTPPath: kong.String("/"),
324+
Type: kong.String("http"),
325+
Timeout: kong.Int(1),
326+
Unhealthy: &kong.Unhealthy{
327+
HTTPFailures: kong.Int(0),
328+
TCPFailures: kong.Int(0),
329+
Timeouts: kong.Int(0),
330+
HTTPStatuses: []int{429, 404, 500, 501, 502, 503, 504, 505},
331+
Interval: kong.Int(0),
332+
},
333+
},
334+
Passive: &kong.PassiveHealthcheck{
335+
Healthy: &kong.Healthy{
336+
HTTPStatuses: []int{200, 201, 202, 203, 204, 205,
337+
206, 207, 208, 226, 300, 301, 302, 303, 304, 305,
338+
306, 307, 308},
339+
Successes: kong.Int(0),
340+
},
341+
Unhealthy: &kong.Unhealthy{
342+
HTTPFailures: kong.Int(0),
343+
TCPFailures: kong.Int(0),
344+
Timeouts: kong.Int(0),
345+
HTTPStatuses: []int{429, 500, 503},
346+
},
347+
},
348+
},
349+
HashOn: kong.String("none"),
350+
HashFallback: kong.String("none"),
351+
HashOnCookiePath: kong.String("/"),
352+
},
353+
},
354+
{
355+
desc: "Healthchecks.Active.HTTPSVerifyCertificate can be set to false",
356+
arg: &kong.Upstream{
357+
Name: kong.String("foo"),
358+
Healthchecks: &kong.Healthcheck{
359+
Active: &kong.ActiveHealthcheck{
360+
Healthy: &kong.Healthy{
361+
Interval: kong.Int(1),
362+
},
363+
HTTPSVerifyCertificate: kong.Bool(false),
364+
},
365+
},
366+
},
367+
want: &kong.Upstream{
368+
Name: kong.String("foo"),
369+
Slots: kong.Int(10000),
370+
Healthchecks: &kong.Healthcheck{
371+
Active: &kong.ActiveHealthcheck{
372+
Concurrency: kong.Int(10),
373+
Healthy: &kong.Healthy{
374+
HTTPStatuses: []int{200, 302},
375+
Interval: kong.Int(1),
376+
Successes: kong.Int(0),
377+
},
258378
HTTPPath: kong.String("/"),
259-
HTTPSVerifyCertificate: kong.Bool(true),
379+
HTTPSVerifyCertificate: kong.Bool(false),
260380
Type: kong.String("http"),
261381
Timeout: kong.Int(1),
262382
Unhealthy: &kong.Unhealthy{
@@ -288,14 +408,15 @@ func TestUpstreamSetTest(t *testing.T) {
288408
},
289409
},
290410
{
291-
desc: "Healthchecks.Active.Healthy.Timeout is not overridden",
411+
desc: "Healthchecks.Active.HTTPSVerifyCertificate can be set to true",
292412
arg: &kong.Upstream{
293413
Name: kong.String("foo"),
294414
Healthchecks: &kong.Healthcheck{
295415
Active: &kong.ActiveHealthcheck{
296416
Healthy: &kong.Healthy{
297417
Interval: kong.Int(1),
298418
},
419+
HTTPSVerifyCertificate: kong.Bool(true),
299420
},
300421
},
301422
},

0 commit comments

Comments
 (0)