-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_test.go
67 lines (58 loc) · 1.71 KB
/
setup_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
66
67
package ks_devops_e2e
import (
"context"
"github.com/kubesphere-sigs/ks-devops-e2e/pkg"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/kubernetes"
"testing"
"time"
)
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecsWithDefaultAndCustomReporters(t,
"Controller Suite",
[]Reporter{})
}
var _ = BeforeSuite(func() {
client, _, err := GetClient()
Expect(err).To(BeNil())
Eventually(func() bool {
if list, err := client.Resource(pkg.GetDeploySchema()).Namespace("kubesphere-devops-system").List(context.TODO(), metav1.ListOptions{}); err == nil {
for i, _ := range list.Items {
item := list.Items[i]
ready := getNestedInt(item.Object, "status", "readyReplicas")
if ready != 1 {
return false
}
}
}
return true
}, time.Second * 120, time.Second).Should(BeTrue())
})
func getNestedString(obj map[string]interface{}, fields ...string) string {
val, found, err := unstructured.NestedString(obj, fields...)
if !found || err != nil {
return ""
}
return val
}
func getNestedInt(obj map[string]interface{}, fields ...string) int64 {
val, found, err := unstructured.NestedInt64(obj, fields...)
if !found || err != nil {
return 0
}
return val
}
func GetClient() (client dynamic.Interface, clientSet *kubernetes.Clientset, err error) {
KubernetesConfigFlags := genericclioptions.NewConfigFlags(false)
if config, err := KubernetesConfigFlags.ToRESTConfig(); err == nil {
client, err = dynamic.NewForConfig(config)
clientSet, err = kubernetes.NewForConfig(config)
}
return
}