Skip to content

Commit

Permalink
optimize structure
Browse files Browse the repository at this point in the history
Signed-off-by: dongjiang1989 <[email protected]>
  • Loading branch information
dongjiang1989 committed Jan 9, 2024
1 parent d8411a0 commit dfbb975
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 71 deletions.
73 changes: 73 additions & 0 deletions test/e2e/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Copyright © 2023 Alibaba Group Holding Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"context"
"testing"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func testInsertAgent(ctx context.Context) func(t *testing.T) {
return func(t *testing.T) {
testCtx := testframework.NewTestCtx(t)
defer testCtx.Cleanup(t)

testNS := testframework.CreateNamespace(context.Background(), t, testCtx)

err := testframework.CreateOrUpdateDaemonSetAndWaitUntilReady(context.Background(), testNS, &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
APIVersion: "apps/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-agent",
Namespace: testNS,
Annotations: map[string]string{},
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"name": "test-agent",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"name": "test-agent",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "agent",
Image: testframework.Image,
},
},
},
},
},
})

if err != nil {
t.Fatal(err)
}
}
}
44 changes: 44 additions & 0 deletions test/e2e/crd_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright © 2023 Alibaba Group Holding Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package e2e

import (
"context"

"testing"

"github.com/alibaba/open-local/pkg/apis/storage"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

func testInsertCRD(ctx context.Context) func(t *testing.T) {
return func(t *testing.T) {
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, func(opts metav1.ListOptions) (runtime.Object, error) {
return testframework.NodeLocalStorageClientV1alpha1.CsiV1alpha1().NodeLocalStorages().List(ctx, opts)
})
if err != nil {
t.Fatal(err)
}
}
}
72 changes: 1 addition & 71 deletions test/e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ import (
"os"
"testing"

"github.com/alibaba/open-local/pkg/apis/storage"
"github.com/alibaba/open-local/test/framework"
"github.com/blang/semver/v4"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)

var (
Expand Down Expand Up @@ -89,73 +84,8 @@ func TestMain(m *testing.M) {
}

func TestE2E(t *testing.T) {
t.Run("TestInstallCRD", testInsertCRD(context.Background()))
testCtx := testframework.NewTestCtx(t)
defer testCtx.Cleanup(t)

t.Run("TestInstallCRD", testInsertCRD(context.Background()))
t.Run("TestInsertAgent", testInsertAgent(context.Background()))
}

func testInsertCRD(ctx context.Context) func(t *testing.T) {
return func(t *testing.T) {
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, func(opts metav1.ListOptions) (runtime.Object, error) {
return testframework.NodeLocalStorageClientV1alpha1.CsiV1alpha1().NodeLocalStorages().List(ctx, opts)
})
if err != nil {
t.Fatal(err)
}
}
}

func testInsertAgent(ctx context.Context) func(t *testing.T) {
return func(t *testing.T) {
testCtx := testframework.NewTestCtx(t)
defer testCtx.Cleanup(t)

testNS := testframework.CreateNamespace(context.Background(), t, testCtx)

err := testframework.CreateOrUpdateDaemonSetAndWaitUntilReady(context.Background(), testNS, &appsv1.DaemonSet{
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
APIVersion: "apps/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "test-agent",
Namespace: testNS,
Annotations: map[string]string{},
},
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"name": "test-agent",
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"name": "test-agent",
},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "agent",
Image: testframework.Image,
},
},
},
},
},
})

if err != nil {
t.Fatal(err)
}
}
}

0 comments on commit dfbb975

Please sign in to comment.