Merge pull request #13 from digitalocean/varsha/add-tests

Add tests around metadata for each check
varsha/versions
Varsha Varadarajan 2019-06-18 14:07:47 -04:00 committed by GitHub
commit e91923530c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 3 deletions

View File

@ -11,14 +11,14 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestMeta(t *testing.T) {
func TestLatestTagCheckMeta(t *testing.T) {
latestTagCheck := latestTagCheck{}
assert.Equal(t, "latest-tag", latestTagCheck.Name())
assert.Equal(t, "Checks if there are pods with container images having latest tag", latestTagCheck.Description())
assert.Equal(t, []string{"basic"}, latestTagCheck.Groups())
}
func TestRegistration(t *testing.T) {
func TestLatestTagCheckRegistration(t *testing.T) {
latestTagCheck := &latestTagCheck{}
check, err := checks.Get("latest-tag")
assert.Equal(t, check, latestTagCheck)

View File

@ -4,12 +4,27 @@ import (
"fmt"
"testing"
"github.com/digitalocean/clusterlint/checks"
"github.com/digitalocean/clusterlint/kube"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestNamespaceCheckMeta(t *testing.T) {
defaultNamespaceCheck := defaultNamespaceCheck{}
assert.Equal(t, "default-namespace", defaultNamespaceCheck.Name())
assert.Equal(t, "Checks if there are any user created k8s objects in the default namespace.", defaultNamespaceCheck.Description())
assert.Equal(t, []string{"basic"}, defaultNamespaceCheck.Groups())
}
func TestNamespaceCheckRegistration(t *testing.T) {
defaultNamespaceCheck := &defaultNamespaceCheck{}
check, err := checks.Get("default-namespace")
assert.Equal(t, check, defaultNamespaceCheck)
assert.Nil(t, err)
}
func TestNamespaceWarning(t *testing.T) {
scenarios := []struct {
name string

View File

@ -4,17 +4,27 @@ import (
"fmt"
"testing"
"github.com/digitalocean/clusterlint/checks"
"github.com/digitalocean/clusterlint/kube"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestGroup(t *testing.T) {
func TestPodSelectorCheckMeta(t *testing.T) {
podSelectorCheck := podSelectorCheck{}
assert.Equal(t, "node-name-pod-selector", podSelectorCheck.Name())
assert.Equal(t, "Checks if there are pods which use kubernetes.io/hostname label in the node selector.", podSelectorCheck.Description())
assert.Equal(t, []string{"doks"}, podSelectorCheck.Groups())
}
func TestPodSelectorCheckRegistration(t *testing.T) {
podSelectorCheck := &podSelectorCheck{}
check, err := checks.Get("node-name-pod-selector")
assert.Equal(t, check, podSelectorCheck)
assert.Nil(t, err)
}
func TestNodeNameError(t *testing.T) {
scenarios := []struct {
name string