Skip to content

Commit

Permalink
add some tests for util/k8sutil/erros.go
Browse files Browse the repository at this point in the history
  • Loading branch information
ObiWahn committed Mar 6, 2018
1 parent f1a4583 commit 4e609ba
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions pkg/util/k8sutil/errors_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit 4e609ba

Please sign in to comment.