refine group e2e test

Signed-off-by: Roland.Ma <rolandma@yunify.com>
This commit is contained in:
Roland.Ma
2021-03-15 02:54:31 +00:00
parent eaf937b15f
commit 8a1c453412
15 changed files with 540 additions and 33 deletions

View File

@@ -19,6 +19,7 @@ package framework
import (
"context"
"fmt"
"time"
"github.com/onsi/ginkgo" //nolint:stylecheck
"github.com/onsi/gomega"
@@ -29,11 +30,21 @@ import (
"k8s.io/client-go/rest"
"kubesphere.io/client-go/client"
"kubesphere.io/client-go/client/generic"
"kubesphere.io/client-go/restclient"
"kubesphere.io/kubesphere/pkg/apis"
"kubesphere.io/kubesphere/pkg/constants"
"kubesphere.io/kubesphere/test/e2e/framework/workspace"
)
const (
// Using the same interval as integration should be fine given the
// minimal load that the apiserver is likely to be under.
PollInterval = 50 * time.Millisecond
// How long to try single API calls (like 'get' or 'list'). Used to prevent
// transient failures from failing tests.
DefaultSingleCallTimeout = 30 * time.Second
)
type Framework struct {
BaseName string
Workspace string
@@ -45,6 +56,7 @@ type Framework struct {
// that the implementation can vary without affecting tests.
type KubeSphereFramework interface {
GenericClient(userAgent string) client.Client
RestClient(userAgent string) *restclient.RestClient
KubeSphereSystemNamespace() string
// Name of the workspace for the current test to target
@@ -54,6 +66,8 @@ type KubeSphereFramework interface {
CreateNamespace(name string) string
// Get Names of the namespaces for the current test to target
GetNamespaceNames() []string
GetScheme() *runtime.Scheme
}
func NewKubeSphereFramework(baseName string) KubeSphereFramework {
@@ -65,6 +79,7 @@ func NewKubeSphereFramework(baseName string) KubeSphereFramework {
if err := scheme.AddToScheme(sch); err != nil {
Failf("unable add Kubernetes APIs to scheme: %v", err)
}
f := &Framework{
BaseName: baseName,
Scheme: sch,
@@ -97,7 +112,7 @@ func CreateTestWorkSpace(client client.Client, baseName string) string {
wspt.GenerateName = fmt.Sprintf("e2e-tests-%v-", baseName)
wspt, err := workspace.CreateWorkspace(client, wspt)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
ginkgo.By(fmt.Sprintf("Created test namespace %s", wspt.Name))
ginkgo.By(fmt.Sprintf("Created test workspace %s", wspt.Name))
return wspt.Name
}
@@ -106,6 +121,7 @@ func (f *Framework) GetNamespaceNames() []string {
}
func (f *Framework) CreateNamespace(name string) string {
name = fmt.Sprintf("%s-%s", f.Workspace, name)
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: name,
@@ -133,19 +149,32 @@ func (f *Framework) KubeSphereSystemNamespace() string {
func (f *Framework) GenericClient(userAgent string) client.Client {
ctx := TestContext
config := &rest.Config{
Host: "127.0.0.1:9090",
Username: "admin",
Password: "P@88w0rd",
}
if ctx.Host != "" {
config = &rest.Config{
Host: ctx.Host,
Username: ctx.Username,
Password: ctx.Password,
}
Host: ctx.Host,
Username: ctx.Username,
Password: ctx.Password,
}
rest.AddUserAgent(config, userAgent)
return generic.NewForConfigOrDie(config, client.Options{Scheme: f.Scheme})
}
func (f *Framework) RestClient(userAgent string) *restclient.RestClient {
ctx := TestContext
config := &rest.Config{
Host: ctx.Host,
Username: ctx.Username,
Password: ctx.Password,
}
c, err := restclient.NewForConfig(config)
if err != nil {
panic(err)
}
return c
}
func (f *Framework) GetScheme() *runtime.Scheme {
return f.Scheme
}