Skip to content

Commit

Permalink
add test case for controller_fetcher and cluster_feeder
Browse files Browse the repository at this point in the history
add test case for controller_fetcher
correct comments
typo
  • Loading branch information
moriadry committed Jul 16, 2019
1 parent 3b358b6 commit 7f644ab
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ func TestLoadPods(t *testing.T) {
expectedConfigUnsupported: nil,
expectedConfigDeprecated: nil,
},
{
name: "no targetRef",
selector: parseLabelSelector("app = test"),
fetchSelectorError: nil,
expectedSelector: labels.Nothing(),
expectedConfigUnsupported: nil,
expectedConfigDeprecated: nil,
},
{
name: "can't decide if top-level-ref",
selector: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/assert"

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
Expand Down Expand Up @@ -117,6 +119,70 @@ func TestControllerFetcher(t *testing.T) {
Name: "test-deployment", Kind: "Deployment", Namespace: "test-namesapce"}}, // Deployment has no parent
expectedError: nil,
},
{
key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-statefulset", Kind: "StatefulSet", Namespace: "test-namesapce"}},
objects: []runtime.Object{&appsv1.StatefulSet{
TypeMeta: metav1.TypeMeta{
Kind: "StatefulSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-statefulset",
Namespace: "test-namesapce",
},
}},
expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-statefulset", Kind: "StatefulSet", Namespace: "test-namesapce"}}, // StatefulSet has no parent
expectedError: nil,
},
{
key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-daemonset", Kind: "DaemonSet", Namespace: "test-namesapce"}},
objects: []runtime.Object{&appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-daemonset",
Namespace: "test-namesapce",
},
}},
expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-daemonset", Kind: "DaemonSet", Namespace: "test-namesapce"}}, // DaemonSet has no parent
expectedError: nil,
},
{
key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-job", Kind: "Job", Namespace: "test-namesapce"}},
objects: []runtime.Object{&batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-job",
Namespace: "test-namesapce",
},
}},
expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-job", Kind: "Job", Namespace: "test-namesapce"}}, // Job has no parent
expectedError: nil,
},
{
key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-rc", Kind: "ReplicationController", Namespace: "test-namesapce"}},
objects: []runtime.Object{&corev1.ReplicationController{
TypeMeta: metav1.TypeMeta{
Kind: "ReplicationController",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-rc",
Namespace: "test-namesapce",
},
}},
expectedKey: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-rc", Kind: "ReplicationController", Namespace: "test-namesapce"}}, // ReplicationController has no parent
expectedError: nil,
},
{
key: &ControllerKeyWithAPIVersion{ControllerKey: ControllerKey{
Name: "test-deployment", Kind: "Deployment", Namespace: "test-namesapce"}},
Expand Down

0 comments on commit 7f644ab

Please sign in to comment.