forked from open-cluster-management-io/sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
118 lines (108 loc) · 2.42 KB
/
Copy pathclient_test.go
File metadata and controls
118 lines (108 loc) · 2.42 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package serviceaccount
import (
"context"
"testing"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
)
func TestNewServiceAccountClient(t *testing.T) {
clusterName := "test-cluster"
saClient := NewServiceAccountClient(clusterName, nil)
if saClient == nil {
t.Fatal("expected non-nil ServiceAccountClient")
}
if saClient.clusterName != clusterName {
t.Errorf("expected clusterName %s, got %s", clusterName, saClient.clusterName)
}
// Verify it implements the interface
var _ corev1client.ServiceAccountInterface = saClient
}
func TestUnsupportedMethods(t *testing.T) {
saClient := &ServiceAccountClient{
clusterName: "test-cluster",
}
ctx := context.Background()
sa := &corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "test-sa",
Namespace: "test-ns",
},
}
tests := []struct {
name string
fn func() error
}{
{
name: "Create",
fn: func() error {
_, err := saClient.Create(ctx, sa, metav1.CreateOptions{})
return err
},
},
{
name: "Update",
fn: func() error {
_, err := saClient.Update(ctx, sa, metav1.UpdateOptions{})
return err
},
},
{
name: "Delete",
fn: func() error {
return saClient.Delete(ctx, "test-sa", metav1.DeleteOptions{})
},
},
{
name: "DeleteCollection",
fn: func() error {
return saClient.DeleteCollection(ctx, metav1.DeleteOptions{}, metav1.ListOptions{})
},
},
{
name: "Get",
fn: func() error {
_, err := saClient.Get(ctx, "test-sa", metav1.GetOptions{})
return err
},
},
{
name: "List",
fn: func() error {
_, err := saClient.List(ctx, metav1.ListOptions{})
return err
},
},
{
name: "Watch",
fn: func() error {
_, err := saClient.Watch(ctx, metav1.ListOptions{})
return err
},
},
{
name: "Patch",
fn: func() error {
_, err := saClient.Patch(ctx, "test-sa", types.StrategicMergePatchType, []byte("{}"), metav1.PatchOptions{})
return err
},
},
{
name: "Apply",
fn: func() error {
_, err := saClient.Apply(ctx, nil, metav1.ApplyOptions{})
return err
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := tt.fn()
if !errors.IsMethodNotSupported(err) {
t.Errorf("expected MethodNotSupported error, got: %v", err)
}
})
}
}