From cac6db5d944919c04bea583c53eb88fd89c4a89a Mon Sep 17 00:00:00 2001 From: xiangpengzhao Date: Tue, 31 Oct 2017 15:48:02 +0800 Subject: [PATCH] Add test case for validateClientConnectionConfiguration. --- cmd/kube-proxy/app/validation_test.go | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cmd/kube-proxy/app/validation_test.go b/cmd/kube-proxy/app/validation_test.go index c860d1f5409..1e1f8384cf9 100644 --- a/cmd/kube-proxy/app/validation_test.go +++ b/cmd/kube-proxy/app/validation_test.go @@ -402,3 +402,40 @@ func TestValidateProxyMode(t *testing.T) { } } } + +func TestValidateClientConnectionConfiguration(t *testing.T) { + newPath := field.NewPath("KubeProxyConfiguration") + + successCases := []componentconfig.ClientConnectionConfiguration{ + { + Burst: 0, + }, + { + Burst: 5, + }, + } + + for _, successCase := range successCases { + if errs := validateClientConnectionConfiguration(successCase, newPath.Child("Burst")); len(errs) != 0 { + t.Errorf("expected success: %v", errs) + } + } + + errorCases := []struct { + ccc componentconfig.ClientConnectionConfiguration + msg string + }{ + { + ccc: componentconfig.ClientConnectionConfiguration{Burst: -5}, + msg: "must be greater than or equal to 0", + }, + } + + for _, errorCase := range errorCases { + if errs := validateClientConnectionConfiguration(errorCase.ccc, newPath.Child("Burst")); len(errs) == 0 { + t.Errorf("expected failure for %s", errorCase.msg) + } else if !strings.Contains(errs[0].Error(), errorCase.msg) { + t.Errorf("unexpected error: %v, expected: %s", errs[0], errorCase.msg) + } + } +}