From f9fa90e7d5cf32aaa83adcda0c2084ac8a93c715 Mon Sep 17 00:00:00 2001 From: dongjiang1989 Date: Thu, 21 Dec 2023 17:07:30 +0800 Subject: [PATCH] add framework cae Signed-off-by: dongjiang1989 --- test/e2e/main_test.go | 13 +++++++---- test/framework/framework.go | 46 +++++++++++++++++++++---------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/test/e2e/main_test.go b/test/e2e/main_test.go index 599f099b..e6113453 100644 --- a/test/e2e/main_test.go +++ b/test/e2e/main_test.go @@ -24,10 +24,11 @@ import ( "os" "testing" - "github.com/blang/semver/v4" - "github.com/alibaba/open-local/pkg/apis/storage" "github.com/alibaba/open-local/test/framework" + "github.com/blang/semver/v4" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" ) var ( @@ -94,11 +95,15 @@ func TestE2E(t *testing.T) { func testInsertCRD(ctx context.Context) func(t *testing.T) { return func(t *testing.T) { - err := testframework.CreateOrUpdateCRDAndWaitUntilReady(ctx, storage.NodeLocalStorageInitConfigName, nil) + err := testframework.CreateOrUpdateCRDAndWaitUntilReady(ctx, storage.NodeLocalStorageInitConfigName, func(opts metav1.ListOptions) (runtime.Object, error) { + return testframework.NodeLocalStorageClientV1alpha1.CsiV1alpha1().NodeLocalStorageInitConfigs().List(ctx, opts) + }) if err != nil { t.Fatal(err) } - err = testframework.CreateOrUpdateCRDAndWaitUntilReady(ctx, storage.NodeLocalStorageListName, nil) + err = testframework.CreateOrUpdateCRDAndWaitUntilReady(ctx, storage.NodeLocalStorageListName, func(opts metav1.ListOptions) (runtime.Object, error) { + return testframework.NodeLocalStorageClientV1alpha1.CsiV1alpha1().NodeLocalStorages().List(ctx, opts) + }) if err != nil { t.Fatal(err) } diff --git a/test/framework/framework.go b/test/framework/framework.go index 9e13bab6..fc7c7876 100644 --- a/test/framework/framework.go +++ b/test/framework/framework.go @@ -21,7 +21,7 @@ import ( "net/http" "time" - "github.com/alibaba/open-local/pkg/apis/storage/v1alpha1" + "github.com/alibaba/open-local/pkg/generated/clientset/versioned" "github.com/blang/semver/v4" apiclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" "k8s.io/client-go/kubernetes" @@ -30,15 +30,15 @@ import ( ) type Framework struct { - KubeClient kubernetes.Interface - APIServerClient apiclient.Interface - *v1alpha1.NodeLocalStorage - HTTPClient *http.Client - MasterHost string - DefaultTimeout time.Duration - RestConfig *rest.Config - Image string - Version semver.Version + KubeClient kubernetes.Interface + APIServerClient apiclient.Interface + NodeLocalStorageClientV1alpha1 versioned.Interface + HTTPClient *http.Client + MasterHost string + DefaultTimeout time.Duration + RestConfig *rest.Config + Image string + Version semver.Version exampleDir string resourcesDir string @@ -66,17 +66,23 @@ func New(kubeconfig, image, exampleDir, resourcesDir string, version semver.Vers return nil, fmt.Errorf("creating http-client failed: %w", err) } + mNodeLocalStorageClientV1alpha1, err := versioned.NewForConfig(config) + if err != nil { + return nil, fmt.Errorf("creating v1alpha1 NodeLocalStorage client failed: %w", err) + } + f := &Framework{ - RestConfig: config, - MasterHost: config.Host, - KubeClient: cli, - APIServerClient: apiCli, - HTTPClient: httpc, - DefaultTimeout: time.Minute, - Version: version, - Image: image, - exampleDir: exampleDir, - resourcesDir: resourcesDir, + RestConfig: config, + MasterHost: config.Host, + KubeClient: cli, + APIServerClient: apiCli, + HTTPClient: httpc, + DefaultTimeout: time.Minute, + Version: version, + Image: image, + exampleDir: exampleDir, + resourcesDir: resourcesDir, + NodeLocalStorageClientV1alpha1: mNodeLocalStorageClientV1alpha1, } return f, nil