-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcluster_test.go
65 lines (56 loc) · 1.57 KB
/
cluster_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package kube
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestClientNode(t *testing.T) {
list, err := mockcli.GetNodes(context.TODO())
require.NoError(t, err)
if len(list.Items) == 0 {
t.Fatal(err)
}
node, err := mockcli.GetNode(context.TODO(), list.Items[0].Name)
require.NoError(t, err)
assert.Equal(t, list.Items[0].Namespace, node.Namespace)
assert.Equal(t, list.Items[0].Name, node.Name)
}
func TestClientNamespace(t *testing.T) {
mocknsname := "mocknamespace"
t.Run("get:namespace", func(t *testing.T) {
ns, err := mockcli.GetNamespace(context.TODO(), "default")
require.NoError(t, err)
assert.Equal(t, "default", ns.Name)
})
t.Run("get:namespace:list", func(t *testing.T) {
list, err := mockcli.GetNamespaces(context.TODO())
require.NoError(t, err)
if len(list.Items) == 0 {
t.Fatal(err)
}
})
t.Run("create:namespace", func(t *testing.T) {
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: mocknsname,
},
}
_, err := mockcli.CreateNamespace(context.TODO(), ns)
require.NoError(t, err)
got, err := mockcli.GetNamespace(context.TODO(), mocknsname)
require.NoError(t, err)
assert.Equal(t, mocknsname, got.Name)
})
t.Run("delete:namespace", func(t *testing.T) {
err := mockcli.DeleteNamespace(context.TODO(), mocknsname)
require.NoError(t, err)
})
}
func TestClientVersion(t *testing.T) {
info, err := mockcli.GetVersion()
require.NoError(t, err)
t.Log(info.String())
}