From 62c766d58d1df8853f40778c548dc353ceffea70 Mon Sep 17 00:00:00 2001 From: Anastasis Andronidis Date: Wed, 3 Jun 2015 18:13:01 +0200 Subject: [PATCH] Add tests --- pkg/kubectl/cmd/util/helpers_test.go | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkg/kubectl/cmd/util/helpers_test.go b/pkg/kubectl/cmd/util/helpers_test.go index cae9b98fd49..cf1e36988da 100644 --- a/pkg/kubectl/cmd/util/helpers_test.go +++ b/pkg/kubectl/cmd/util/helpers_test.go @@ -25,7 +25,9 @@ import ( "testing" "github.com/GoogleCloudPlatform/kubernetes/pkg/api" + "github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors" "github.com/GoogleCloudPlatform/kubernetes/pkg/runtime" + "github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors" ) func TestMerge(t *testing.T) { @@ -399,3 +401,36 @@ func TestReadConfigData(t *testing.T) { } } } + +func TestCheckInvalidErr(t *testing.T) { + tests := []struct { + err error + expected string + }{ + { + errors.NewInvalid("Invalid1", "invalidation", fielderrors.ValidationErrorList{fielderrors.NewFieldInvalid("Cause", "single", "details")}), + `Error from server: Invalid1 "invalidation" is invalid: Cause: invalid value 'single': details`, + }, + { + errors.NewInvalid("Invalid2", "invalidation", fielderrors.ValidationErrorList{fielderrors.NewFieldInvalid("Cause", "multi1", "details"), fielderrors.NewFieldInvalid("Cause", "multi2", "details")}), + `Error from server: Invalid2 "invalidation" is invalid: [Cause: invalid value 'multi1': details, Cause: invalid value 'multi2': details]`, + }, + { + errors.NewInvalid("Invalid3", "invalidation", fielderrors.ValidationErrorList{}), + `Error from server: Invalid3 "invalidation" is invalid: `, + }, + } + + var errReturned string + errHandle := func(err string) { + errReturned = err + } + + for _, test := range tests { + checkErr(test.err, errHandle) + + if errReturned != test.expected { + t.Fatalf("Got: %s, expected: %s", errReturned, test.expected) + } + } +}