Commit 9d0da861 authored by Daniel Hochman's avatar Daniel Hochman
Browse files

tests

parent d881392f
Showing with 49 additions and 22 deletions
+49 -22
package k8s
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"k8s.io/client-go/kubernetes/fake"
)
func TestClientsetManager(t *testing.T) {
fcs := fake.NewSimpleClientset()
m := managerImpl{clientsets: map[string]*ctxClientsetImpl{
"core-0": NewContextClientset("core-namespace", "core-cluster-0", fcs).(*ctxClientsetImpl),
"core-1a": NewContextClientset("core-namespace", "core-cluster-1", fcs).(*ctxClientsetImpl),
"core-1b": NewContextClientset("core-namespace", "core-cluster-1", fcs).(*ctxClientsetImpl),
}}
// No match found.
cs, err := m.GetK8sClientset(context.Background(), "foo", "foo", "foo")
assert.Error(t, err)
assert.Contains(t, err.Error(), "not found")
assert.Nil(t, cs)
// Clientset found but cluster does not match.
cs, err = m.GetK8sClientset(context.Background(), "core-0", "foo", "foo")
assert.Error(t, err)
assert.Contains(t, err.Error(), "does not match clientset")
assert.Nil(t, cs)
// Clientset match and check namespace.
cs, err = m.GetK8sClientset(context.Background(), "core-0", "core-cluster-0", "foo")
assert.NoError(t, err)
assert.NotNil(t, cs)
assert.Equal(t, "foo", cs.Namespace())
assert.Equal(t, "core-cluster-0", cs.Cluster())
// Cluster match.
cs, err = m.GetK8sClientset(context.Background(), "undefined", "core-cluster-0", "foo")
assert.NoError(t, err)
assert.NotNil(t, cs)
// Multiple cluster match error.
cs, err = m.GetK8sClientset(context.Background(), "undefined", "core-cluster-1", "")
assert.Error(t, err)
assert.Contains(t, err.Error(), "impossible to determine")
assert.Nil(t, cs)
}
......@@ -202,30 +202,9 @@ func TestListPods(t *testing.T) {
}},
},
}
// Clientset not found
result, err := s.ListPods(
context.Background(),
"unknown-clientset",
"testing-cluster",
"testing-namespace",
&k8sv1.ListOptions{},
)
assert.Error(t, err)
assert.Nil(t, result)
// No matching pods
result, err = s.ListPods(
context.Background(),
"testing-clientset",
"testing-cluster",
"testing-namespace",
&k8sv1.ListOptions{Labels: map[string]string{"unknown-annotation": "bar"}},
)
assert.NoError(t, err)
assert.Empty(t, result)
// Two matching pods
result, err = s.ListPods(
result, err := s.ListPods(
context.Background(),
"testing-clientset",
"testing-cluster",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment