From 6e18d66fd0e8ee3ff95e397298f73f86167c5099 Mon Sep 17 00:00:00 2001 From: Vighneswar Rao Bojja Date: Sun, 25 Aug 2019 07:27:59 +0530 Subject: [PATCH] Address review comments --- internal/configs/virtualserver.go | 14 ++++++------- internal/configs/virtualserver_test.go | 28 +++++++++++++------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/internal/configs/virtualserver.go b/internal/configs/virtualserver.go index 2293d29332..9cc5ac0b37 100644 --- a/internal/configs/virtualserver.go +++ b/internal/configs/virtualserver.go @@ -17,7 +17,6 @@ const nginx502Server = "unix:/var/run/nginx-502-server.sock" var incompatibleLBMethodsForSlowStart = map[string]bool{ "random": true, "ip_hash": true, - "hash": true, "random two": true, "random two least_conn": true, "random two least_time=header": true, @@ -363,18 +362,17 @@ func generateUpstream(upstreamName string, upstream conf_v1alpha1.Upstream, isEx } return version2.Upstream{ - Name: upstreamName, - Servers: upsServers, - LBMethod: lbMethod, - Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive), + Name: upstreamName, + Servers: upsServers, + LBMethod: lbMethod, + Keepalive: generateIntFromPointer(upstream.Keepalive, cfgParams.Keepalive), UpstreamZoneSize: cfgParams.UpstreamZoneSize, } } func generateSlowStartForPlus(upstream conf_v1alpha1.Upstream, lbMethod string) string { - slowStart := upstream.SlowStart - if slowStart == "" { + if upstream.SlowStart == "" { return "" } @@ -388,7 +386,7 @@ func generateSlowStartForPlus(upstream conf_v1alpha1.Upstream, lbMethod string) return "" } - return slowStart + return upstream.SlowStart } func generateLBMethod(method string, defaultMethod string) string { diff --git a/internal/configs/virtualserver_test.go b/internal/configs/virtualserver_test.go index a4432dab9a..429f8eae4e 100644 --- a/internal/configs/virtualserver_test.go +++ b/internal/configs/virtualserver_test.go @@ -1966,24 +1966,24 @@ func TestGenerateEndpointsForUpstream(t *testing.T) { func TestGenerateSlowStartForPlusWithInCompatibleLBMethods(t *testing.T) { serviceName := "test-slowstart-with-incompatible-LBMethods" + upstream := conf_v1alpha1.Upstream{Service: serviceName, Port: 80, SlowStart: "10s"} + expected := "" - tests := []struct { - upstream conf_v1alpha1.Upstream - expected string - }{ - { - upstream: conf_v1alpha1.Upstream{Service: serviceName, Port: 80, SlowStart: "10s"}, - expected: "", - }, + var tests = []string{ + "random", + "ip_hash", + "hash", + "random two", + "random two least_conn", + "random two least_time=header", + "random two least_time=last_byte", } - for _, test := range tests { - for lbMethod, _ := range incompatibleLBMethodsForSlowStart { - result := generateSlowStartForPlus(test.upstream, lbMethod) + for _, lbMethod := range tests { + result := generateSlowStartForPlus(upstream, lbMethod) - if !reflect.DeepEqual(result, test.expected) { - t.Errorf("generateSlowStartForPlus returned %v, but expected %v", result, test.expected) - } + if !reflect.DeepEqual(result, expected) { + t.Errorf("generateSlowStartForPlus returned %v, but expected %v", result, expected) } }