Files
polaris/pkg/kube/resources_test.go
Bobby Brennan 520d6572e4 Add ability to audit a directory of files (#70)
* refactor kubernetes API usage

* add ability to audit directory

* refactor a bit

* fix return statement

* fix main.go

* add ability to audit multiple resources in a single file
2019-05-07 12:42:57 -04:00

44 lines
1.7 KiB
Go

package kube
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestGetResourcesFromPath(t *testing.T) {
resources, err := CreateResourceProviderFromPath("./test_files/test_1")
assert.Equal(t, nil, err, "Error should be nil")
assert.Equal(t, "unknown", resources.ServerVersion, "Server version should be unknown")
assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes")
assert.Equal(t, 1, len(resources.Deployments), "Should have a deployment")
assert.Equal(t, "ubuntu", resources.Deployments[0].Spec.Template.Spec.Containers[0].Name)
assert.Equal(t, 1, len(resources.Namespaces), "Should have a namespace")
assert.Equal(t, "two", resources.Namespaces[0].ObjectMeta.Name)
assert.Equal(t, 2, len(resources.Pods), "Should have two pods")
assert.Equal(t, "", resources.Pods[0].ObjectMeta.Namespace, "Should have one pod in default namespace")
assert.Equal(t, "two", resources.Pods[1].ObjectMeta.Namespace, "Should have one pod in namespace 'two'")
}
func TestGetMultipleResourceFromSingleFile(t *testing.T) {
resources, err := CreateResourceProviderFromPath("./test_files/test_2/multi.yaml")
assert.Equal(t, nil, err, "Error should be nil")
assert.Equal(t, "unknown", resources.ServerVersion, "Server version should be unknown")
assert.Equal(t, 0, len(resources.Nodes), "Should not have any nodes")
assert.Equal(t, 1, len(resources.Deployments), "Should have a deployment")
assert.Equal(t, "dashboard", resources.Deployments[0].Spec.Template.Spec.Containers[0].Name)
assert.Equal(t, 2, len(resources.Namespaces), "Should have a namespace")
assert.Equal(t, "fairwinds", resources.Namespaces[0].ObjectMeta.Name)
assert.Equal(t, "fairwinds-2", resources.Namespaces[1].ObjectMeta.Name)
}