Skip to content

Commit

Permalink
add framework cae
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang1989 <[email protected]>
  • Loading branch information
dongjiang1989 committed Dec 21, 2023
1 parent 87c5e2e commit f9fa90e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
13 changes: 9 additions & 4 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
Expand Down
46 changes: 26 additions & 20 deletions test/framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f9fa90e

Please sign in to comment.