mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Add tests
This commit is contained in:
parent
b7c485ee9a
commit
62c766d58d
@ -25,7 +25,9 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
|
||||||
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMerge(t *testing.T) {
|
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: <nil>`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user