From 4e609bad79c558559a2fad5c2d78717c66881c34 Mon Sep 17 00:00:00 2001 From: Jan Christoph Uhde Date: Tue, 6 Mar 2018 10:59:52 +0100 Subject: [PATCH] add some tests for util/k8sutil/erros.go --- pkg/util/k8sutil/errors_test.go | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pkg/util/k8sutil/errors_test.go diff --git a/pkg/util/k8sutil/errors_test.go b/pkg/util/k8sutil/errors_test.go new file mode 100644 index 000000000..5353cd7b4 --- /dev/null +++ b/pkg/util/k8sutil/errors_test.go @@ -0,0 +1,34 @@ +package k8sutil + +import ( + "os" + "testing" + + "github.com/stretchr/testify/assert" + + apierrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" +) + +var ( + conflictError = apierrors.NewConflict(schema.GroupResource{"groupName", "resourceName"}, "something", os.ErrInvalid) + existsError = apierrors.NewAlreadyExists(schema.GroupResource{"groupName", "resourceName"}, "something") + invalidError = apierrors.NewInvalid(schema.GroupKind{"groupName", "kindName"}, "something", field.ErrorList{}) + notFoundError = apierrors.NewNotFound(schema.GroupResource{"groupName", "resourceName"}, "something") +) + +func TestIsAlreadyExists(t *testing.T) { + assert.False(t, IsAlreadyExists(conflictError)) + assert.True(t, IsAlreadyExists(existsError)) +} + +func TestIsConflict(t *testing.T) { + assert.False(t, IsConflict(existsError)) + assert.True(t, IsConflict(conflictError)) +} + +func TestIsNotFound(t *testing.T) { + assert.False(t, IsNotFound(invalidError)) + assert.True(t, IsNotFound(notFoundError)) +}