From e520102bbca7b5b0bb2a13f9d3a0919f2e0841cc Mon Sep 17 00:00:00 2001
From: Vee Zhang <veezhang@126.com>
Date: Tue, 10 Oct 2023 05:22:54 -0500
Subject: [PATCH] =?UTF-8?q?feat:=20e2e=20add=20label,=20load=20ldbc=20flag?=
 =?UTF-8?q?=20and=20write=20the=20case=20in=20a=20separate=20=E2=80=A6=20(?=
 =?UTF-8?q?#324)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 tests/e2e/main_test.go                        |   3 +
 tests/e2e/nebulacluster_basic_test.go         | 135 +++++++++++
 ...er-basic_test.go => nebulacluster_test.go} | 211 +++++-------------
 3 files changed, 190 insertions(+), 159 deletions(-)
 create mode 100644 tests/e2e/nebulacluster_basic_test.go
 rename tests/e2e/{nebulacluster-basic_test.go => nebulacluster_test.go} (53%)

diff --git a/tests/e2e/main_test.go b/tests/e2e/main_test.go
index 69b3084a..03039067 100644
--- a/tests/e2e/main_test.go
+++ b/tests/e2e/main_test.go
@@ -37,6 +37,9 @@ import (
 
 const (
 	ImagePullSecretName = "image-pull-secret.e2e"
+
+	LabelKeyCategory = "category"
+	LabelKeyCase     = "case"
 )
 
 var (
diff --git a/tests/e2e/nebulacluster_basic_test.go b/tests/e2e/nebulacluster_basic_test.go
new file mode 100644
index 00000000..045f8285
--- /dev/null
+++ b/tests/e2e/nebulacluster_basic_test.go
@@ -0,0 +1,135 @@
+package e2e
+
+import (
+	"github.com/vesoft-inc/nebula-operator/tests/e2e/envfuncsext"
+	"sigs.k8s.io/e2e-framework/third_party/helm"
+)
+
+var testCasesBasic = []ncTestCase{
+	{
+		Name: "default 2-3-3",
+		Labels: map[string]string{
+			LabelKeyCategory: "basic",
+		},
+		InstallWaitNCOptions: []envfuncsext.NebulaClusterOption{
+			envfuncsext.WithNebulaClusterReadyFuncs(
+				envfuncsext.NebulaClusterReadyFuncForReplicas(2, 3, 3),
+				envfuncsext.DefaultNebulaClusterReadyFunc,
+			),
+		},
+		LoadLDBC: true,
+		UpgradeCases: []ncTestUpgradeCase{
+			{
+				Name:        "scale out [graphd, storaged]: 4-3-4",
+				UpgradeFunc: nil,
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=4",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=4",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(4, 3, 4),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+			{
+				Name:        "scale out  [graphd]: 5-3-4",
+				UpgradeFunc: nil,
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=5",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=4",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(5, 3, 4),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+			{
+				Name:        "scale out [storaged]: 5-3-5",
+				UpgradeFunc: nil,
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=5",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=5",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(5, 3, 5),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+			{
+				Name: "scale in [graphd, storaged]: 3-3-4",
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=3",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=4",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(3, 3, 4),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+			{
+				Name: "scale in [storaged]: 3-3-3",
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=3",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=3",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(3, 3, 3),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+			{
+				Name: "scale in[graphd]: 2-3-3",
+				UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterHelmRawOptions(
+						helm.WithArgs(
+							"--set", "nebula.graphd.replicas=2",
+							"--set", "nebula.metad.replicas=3",
+							"--set", "nebula.storaged.replicas=3",
+						),
+					),
+				},
+				UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
+					envfuncsext.WithNebulaClusterReadyFuncs(
+						envfuncsext.NebulaClusterReadyFuncForReplicas(2, 3, 3),
+						envfuncsext.DefaultNebulaClusterReadyFunc,
+					),
+				},
+			},
+		},
+	},
+}
diff --git a/tests/e2e/nebulacluster-basic_test.go b/tests/e2e/nebulacluster_test.go
similarity index 53%
rename from tests/e2e/nebulacluster-basic_test.go
rename to tests/e2e/nebulacluster_test.go
index e81398af..59e96f82 100644
--- a/tests/e2e/nebulacluster-basic_test.go
+++ b/tests/e2e/nebulacluster_test.go
@@ -34,155 +34,46 @@ import (
 	"github.com/vesoft-inc/nebula-operator/tests/e2e/envfuncsext"
 )
 
-func TestNebulaClusterBasic(t *testing.T) {
-	type tmpTestUpgradeCase struct {
-		Name                 string
-		UpgradeFunc          features.Func // Customize the upgrade function, otherwise use the default upgrade with UpgradeNCOptions.
-		UpgradeNCOptions     []envfuncsext.NebulaClusterOption
-		UpgradeWaitNCOptions []envfuncsext.NebulaClusterOption
-	}
-	type tmpTestCase struct {
+var ncGlobalTestCases []ncTestCase
+
+func init() {
+	ncGlobalTestCases = append(ncGlobalTestCases, testCasesBasic...)
+}
+
+type (
+	ncTestCase struct {
 		Name                 string
+		Labels               map[string]string
 		InstallNCOptions     []envfuncsext.NebulaClusterOption
 		InstallWaitNCOptions []envfuncsext.NebulaClusterOption
-		UpgradeCases         []tmpTestUpgradeCase
+		LoadLDBC             bool
+		UpgradeCases         []ncTestUpgradeCase
 	}
 
-	testCases := []tmpTestCase{
-		{
-			Name: "default 2-3-3",
-			InstallWaitNCOptions: []envfuncsext.NebulaClusterOption{
-				envfuncsext.WithNebulaClusterReadyFuncs(
-					envfuncsext.NebulaClusterReadyFuncForReplicas(2, 3, 3),
-					envfuncsext.DefaultNebulaClusterReadyFunc,
-				),
-			},
-			UpgradeCases: []tmpTestUpgradeCase{
-				{
-					Name:        "scale out [graphd, storaged]: 4-3-4",
-					UpgradeFunc: nil,
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=4",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=4",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(4, 3, 4),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-				{
-					Name:        "scale out  [graphd]: 5-3-4",
-					UpgradeFunc: nil,
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=5",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=4",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(5, 3, 4),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-				{
-					Name:        "scale out [storaged]: 5-3-5",
-					UpgradeFunc: nil,
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=5",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=5",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(5, 3, 5),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-				{
-					Name: "scale in [graphd, storaged]: 3-3-4",
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=3",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=4",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(3, 3, 4),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-				{
-					Name: "scale in [storaged]: 3-3-3",
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=3",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=3",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(3, 3, 3),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-				{
-					Name: "scale in[graphd]: 2-3-3",
-					UpgradeNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterHelmRawOptions(
-							helm.WithArgs(
-								"--set", "nebula.graphd.replicas=2",
-								"--set", "nebula.metad.replicas=3",
-								"--set", "nebula.storaged.replicas=3",
-							),
-						),
-					},
-					UpgradeWaitNCOptions: []envfuncsext.NebulaClusterOption{
-						envfuncsext.WithNebulaClusterReadyFuncs(
-							envfuncsext.NebulaClusterReadyFuncForReplicas(2, 3, 3),
-							envfuncsext.DefaultNebulaClusterReadyFunc,
-						),
-					},
-				},
-			},
-		},
+	ncTestUpgradeCase struct {
+		Name                 string
+		UpgradeFunc          features.Func // Customize the upgrade function, otherwise use the default upgrade with UpgradeNCOptions.
+		UpgradeNCOptions     []envfuncsext.NebulaClusterOption
+		UpgradeWaitNCOptions []envfuncsext.NebulaClusterOption
 	}
+)
 
-	testFeatures := make([]features.Feature, 0, len(testCases))
-	for caseIdx := range testCases {
+func TestNebulaCluster(t *testing.T) {
+	testFeatures := make([]features.Feature, 0, len(ncGlobalTestCases))
+	for caseIdx := range ncGlobalTestCases {
 		caseIdx := caseIdx
-		tc := testCases[caseIdx]
+		tc := ncGlobalTestCases[caseIdx]
 
 		namespace := envconf.RandomName(fmt.Sprintf("e2e-nc-%d", caseIdx), 32)
 		name := envconf.RandomName(fmt.Sprintf("e2e-nc-%d", caseIdx), 32)
 
 		feature := features.New(fmt.Sprintf("Create NebulaCluster %s", tc.Name))
 
+		feature.WithLabel(LabelKeyCase, tc.Name)
+		for key, value := range tc.Labels {
+			feature.WithLabel(key, value)
+		}
+
 		feature.Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
 			var err error
 			ctx, err = envfuncs.CreateNamespace(namespace)(ctx, cfg)
@@ -230,33 +121,35 @@ func TestNebulaClusterBasic(t *testing.T) {
 			},
 		)
 
-		feature.Assess("Load LDBC-SNB dataset",
-			func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
-				klog.V(4).InfoS("Loading LDBC-SNB dataset", "namespace", namespace, "name", name)
+		if tc.LoadLDBC {
+			feature.Assess("Load LDBC-SNB dataset",
+				func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
+					klog.V(4).InfoS("Loading LDBC-SNB dataset", "namespace", namespace, "name", name)
 
-				var err error
+					var err error
 
-				ncCtxValue := envfuncsext.GetNebulaClusterCtxValue(ctx)
-				nc := &appsv1alpha1.NebulaCluster{}
-				if err = cfg.Client().Resources().Get(ctx, ncCtxValue.Name, ncCtxValue.Namespace, nc); err != nil {
-					t.Errorf("failed to get NebulaCluster %v", err)
-				}
+					ncCtxValue := envfuncsext.GetNebulaClusterCtxValue(ctx)
+					nc := &appsv1alpha1.NebulaCluster{}
+					if err = cfg.Client().Resources().Get(ctx, ncCtxValue.Name, ncCtxValue.Namespace, nc); err != nil {
+						t.Errorf("failed to get NebulaCluster %v", err)
+					}
 
-				ctx, err = envfuncsext.ImportLDBC(
-					envfuncsext.WithImporterName(nc.Name+"-import-ldbc"),
-					envfuncsext.WithImporterNamespace(nc.Namespace),
-					envfuncsext.WithImporterClientAddress(nc.GraphdComponent().GetConnAddress(appsv1alpha1.GraphdPortNameThrift)),
-					envfuncsext.WithImporterWaitOptions(
-						wait.WithInterval(time.Second*5),
-						wait.WithTimeout(time.Minute*5),
-					),
-				)(ctx, cfg)
-				if err != nil {
-					t.Errorf("failed to create importer to load data %v", err)
-				}
-				return ctx
-			},
-		)
+					ctx, err = envfuncsext.ImportLDBC(
+						envfuncsext.WithImporterName(nc.Name+"-import-ldbc"),
+						envfuncsext.WithImporterNamespace(nc.Namespace),
+						envfuncsext.WithImporterClientAddress(nc.GraphdComponent().GetConnAddress(appsv1alpha1.GraphdPortNameThrift)),
+						envfuncsext.WithImporterWaitOptions(
+							wait.WithInterval(time.Second*5),
+							wait.WithTimeout(time.Minute*5),
+						),
+					)(ctx, cfg)
+					if err != nil {
+						t.Errorf("failed to create importer to load data %v", err)
+					}
+					return ctx
+				},
+			)
+		}
 
 		for upgradeCaseIdx := range tc.UpgradeCases {
 			upgradeCase := tc.UpgradeCases[upgradeCaseIdx]