Add a test for when a validation function is passed.

Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
Matt Moyer 2020-07-24 11:52:38 -05:00
parent 924eb1abaa
commit 6fe7a4c9dc

View File

@ -8,6 +8,7 @@ package loginrequest
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"testing" "testing"
"time" "time"
@ -235,6 +236,21 @@ func TestCreateFailsWhenTokenValueIsEmptyInRequest(t *testing.T) {
`.placeholder.suzerain-io.github.io "request name" is invalid: spec.token.value: Required value: token must be supplied`) `.placeholder.suzerain-io.github.io "request name" is invalid: spec.token.value: Required value: token must be supplied`)
} }
func TestCreateFailsWhenValidationFails(t *testing.T) {
storage := NewREST(&FakeToken{})
response, err := storage.Create(
context.Background(),
validLoginRequest(),
func(ctx context.Context, obj runtime.Object) error {
return fmt.Errorf("some validation error")
},
&metav1.CreateOptions{
DryRun: []string{},
})
require.Nil(t, response)
require.EqualError(t, err, "some validation error")
}
func TestCreateFailsWhenRequestOptionsDryRunIsNotEmpty(t *testing.T) { func TestCreateFailsWhenRequestOptionsDryRunIsNotEmpty(t *testing.T) {
response, err := NewREST(&FakeToken{}).Create( response, err := NewREST(&FakeToken{}).Create(
genericapirequest.NewContext(), genericapirequest.NewContext(),