From 4962acebedf38fa21061f2c197cbd79bfbab7c0c Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Mon, 11 Sep 2023 10:23:50 +0800 Subject: [PATCH 1/7] clean the unused code, prune dependency github.com/stretchr/testify Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/cmd/commands/client/ls_metadatas.go | 9 -- .../deploy/deploy_recover_job_test.go | 2 - k8s/cmd/commands/sidecar/inject_test.go | 2 - k8s/cmd/commands/util/format.go | 4 - k8s/cmd/commands/util/manifests_test.go | 34 ++-- k8s/cmd/commands/util/parse_test.go | 145 +++++++++++++----- k8s/cmd/commands/util/template_test.go | 9 +- k8s/cmd/commands/util/usage/md_docs.go | 5 - k8s/go.mod | 2 - 9 files changed, 135 insertions(+), 77 deletions(-) diff --git a/k8s/cmd/commands/client/ls_metadatas.go b/k8s/cmd/commands/client/ls_metadatas.go index e19b42ad..6c45af16 100644 --- a/k8s/cmd/commands/client/ls_metadatas.go +++ b/k8s/cmd/commands/client/ls_metadatas.go @@ -16,8 +16,6 @@ limitations under the License. package client import ( - "os" - "github.com/spf13/cobra" "github.com/v6d-io/v6d/k8s/cmd/commands/flags" "github.com/v6d-io/v6d/k8s/cmd/commands/util" @@ -89,10 +87,3 @@ func init() { flags.ApplyLsOpts(lsMetadatas) flags.ApplyOutputOpts(lsMetadatas) } - -func DisableStdout() *os.File { - stdout := os.Stdout - os.Stdout, _ = os.Open(os.DevNull) - - return stdout -} diff --git a/k8s/cmd/commands/deploy/deploy_recover_job_test.go b/k8s/cmd/commands/deploy/deploy_recover_job_test.go index 65adf9e4..c72183dc 100644 --- a/k8s/cmd/commands/deploy/deploy_recover_job_test.go +++ b/k8s/cmd/commands/deploy/deploy_recover_job_test.go @@ -17,7 +17,6 @@ package deploy import ( "context" - "fmt" "reflect" "testing" @@ -314,7 +313,6 @@ func Test_getRecoverObjectsFromTemplate_third(t *testing.T) { } for i := range got { if !reflect.DeepEqual(*got[i], *(tt.want)[i]) { - fmt.Println(*got[i]) t.Errorf("getRecoverObjectsFromTemplate() = %+v, want %+v", got, tt.want) } } diff --git a/k8s/cmd/commands/sidecar/inject_test.go b/k8s/cmd/commands/sidecar/inject_test.go index 03ea0439..6f3ba094 100644 --- a/k8s/cmd/commands/sidecar/inject_test.go +++ b/k8s/cmd/commands/sidecar/inject_test.go @@ -503,8 +503,6 @@ spec: return } if !reflect.DeepEqual(got, tt.want) { - fmt.Println(got) - fmt.Println(tt.want) t.Errorf("GetWorkloadObj() = %v, want %v", got, tt.want) } }) diff --git a/k8s/cmd/commands/util/format.go b/k8s/cmd/commands/util/format.go index 17f2a423..ac0ba586 100644 --- a/k8s/cmd/commands/util/format.go +++ b/k8s/cmd/commands/util/format.go @@ -29,10 +29,6 @@ func Examples(examples string) string { return formatter{examples}.trim().tab().indent().string } -func Docs(yamls string) string { - return formatter{yamls}.doc().string -} - type formatter struct { string } diff --git a/k8s/cmd/commands/util/manifests_test.go b/k8s/cmd/commands/util/manifests_test.go index 573a13d7..2d17fd99 100644 --- a/k8s/cmd/commands/util/manifests_test.go +++ b/k8s/cmd/commands/util/manifests_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/client" @@ -217,8 +216,9 @@ func Test_ApplyManifests(t *testing.T) { pod.SetKind("Pod") pod.SetAPIVersion("v1") err := c.Get(context.Background(), client.ObjectKey{Name: "my-pod-1", Namespace: "vineyard-system"}, pod) - assert.Nil(t, err) - + if err != nil { + t.Errorf("Error: %d", err) + } } } @@ -279,7 +279,9 @@ func Test_DeleteManifests(t *testing.T) { pod.SetKind("Pod") pod.SetAPIVersion("v1") err := c.Get(context.Background(), client.ObjectKey{Name: "my-pod-1", Namespace: "vineyard-system"}, pod) - assert.NotNil(t, err) + if err == nil { + t.Errorf("There should exist an error") + } } } @@ -492,7 +494,9 @@ func Test_ApplyManifestsWithOwnerRef(t *testing.T) { // Test with valid inputs err := ApplyManifestsWithOwnerRef(c, objs, "Job", "Role,Rolebinding") - assert.Nil(t, err) + if err != nil { + t.Errorf("Error: %d", err) + } // Check if OwnerReference was set for "Role" kind RoleBinding := &unstructured.Unstructured{} @@ -500,14 +504,24 @@ func Test_ApplyManifestsWithOwnerRef(t *testing.T) { RoleBinding.SetAPIVersion("rbac.authorization.k8s.io/v1") err = c.Get(context.Background(), client.ObjectKey{Name: "vineyard-backup", Namespace: "vineyard-system"}, RoleBinding) - assert.Nil(t, err) + if err != nil { + t.Errorf("Error: %d", err) + } time.Sleep(2 * time.Second) ownerRefs := RoleBinding.GetOwnerReferences() - assert.Equal(t, 1, len(ownerRefs)) - assert.Equal(t, "Job", ownerRefs[0].Kind) - assert.Equal(t, "vineyard-backup", ownerRefs[0].Name) + if !reflect.DeepEqual(1, len(ownerRefs)) { + t.Errorf("got %+v, want %+v", len(ownerRefs), 1) + } + if !reflect.DeepEqual("Job", ownerRefs[0].Kind) { + t.Errorf("got %+v, want %+v", ownerRefs[0].Kind, "Job") + } + if !reflect.DeepEqual("vineyard-backup", ownerRefs[0].Name) { + t.Errorf("got %+v, want %+v", ownerRefs[0].Name, "vineyard-backup") + } // Test with unsupported kind in refKind err = ApplyManifestsWithOwnerRef(c, objs, "Job", "Unsupported") - assert.Nil(t, err) + if err != nil { + t.Errorf("Error: %d", err) + } } diff --git a/k8s/cmd/commands/util/parse_test.go b/k8s/cmd/commands/util/parse_test.go index 5670f53a..c15abfb4 100644 --- a/k8s/cmd/commands/util/parse_test.go +++ b/k8s/cmd/commands/util/parse_test.go @@ -16,9 +16,9 @@ limitations under the License. package util import ( + "reflect" "testing" - "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,20 +27,28 @@ import ( func TestConvertToJson(t *testing.T) { // Test case 1: Valid JSON input jsonStr := `{"name":"John", "age": 31}` - expectedJSON := `{"name":"John","age":31}` + expectedJSON := `{"name":"John", "age": 31}` result, err := ConvertToJson(jsonStr) - assert.NoError(t, err) - assert.JSONEq(t, expectedJSON, result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedJSON, result) { + t.Errorf("got %+v, want %+v", result, expectedJSON) + } // Test case 2: Valid YAML input yamlStr := ` name: John age: 32 ` - expectedYAML := `{"name":"John","age":32}` + expectedYAML := `{"age":32,"name":"John"}` result, err = ConvertToJson(yamlStr) - assert.NoError(t, err) - assert.JSONEq(t, expectedYAML, result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedYAML, result) { + t.Errorf("got %+v, want %+v", result, expectedYAML) + } } @@ -51,9 +59,12 @@ func TestConvertToYaml(t *testing.T) { name: John ` result, err := ConvertToYaml(jsonStr) - assert.NoError(t, err) - assert.Equal(t, expectedYAML, result) - + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedYAML, result) { + t.Errorf("got %+v, want %+v", result, expectedYAML) + } } func TestParseEnvs(t *testing.T) { @@ -64,26 +75,42 @@ func TestParseEnvs(t *testing.T) { {Name: "KEY2=Value2", Value: "KEY2=Value2"}, } result, err := ParseEnvs(envArray) - assert.NoError(t, err) - assert.Equal(t, expectedEnvs, result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedEnvs, result) { + t.Errorf("got %+v, want %+v", result, expectedEnvs) + } // Test case 2: Invalid env string without "=" separator invalidEnv := []string{"KEY1:Value1"} _, err = ParseEnvs(invalidEnv) - assert.Error(t, err) - assert.EqualError(t, err, "invalid env string") + if err == nil { + t.Errorf("There should exist an error") + } + if !reflect.DeepEqual(err.Error(), "invalid env string") { + t.Errorf("got wrong err: %+v", err) + } // Test case 3: Invalid env with empty name emptyNameEnv := []string{"=Value1"} _, err = ParseEnvs(emptyNameEnv) - assert.Error(t, err) - assert.EqualError(t, err, "the name of env can not be empty") + if err == nil { + t.Errorf("There should exist an error") + } + if !reflect.DeepEqual(err.Error(), "the name of env can not be empty") { + t.Errorf("got wrong err: %+v", err) + } // Test case 4: Invalid env with empty value emptyValueEnv := []string{"KEY1="} _, err = ParseEnvs(emptyValueEnv) - assert.Error(t, err) - assert.EqualError(t, err, "the value of env can not be empty") + if err == nil { + t.Errorf("There should exist an error") + } + if !reflect.DeepEqual(err.Error(), "the value of env can not be empty") { + t.Errorf("got wrong err: %+v", err) + } } func TestParsePVSpec(t *testing.T) { @@ -105,8 +132,12 @@ func TestParsePVSpec(t *testing.T) { PersistentVolumeReclaimPolicy: corev1.PersistentVolumeReclaimRetain, } result, err := ParsePVSpec(pvSpec) - assert.NoError(t, err) - assert.Equal(t, expectedSpec, *result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedSpec, *result) { + t.Errorf("got %+v, want %+v", *result, expectedSpec) + } // Test case 2: Invalid PV spec invalidSpec := `{ @@ -117,7 +148,9 @@ func TestParsePVSpec(t *testing.T) { "persistentVolumeReclaimPolicy": "Retain" }` _, err = ParsePVSpec(invalidSpec) - assert.Error(t, err) + if err == nil { + t.Errorf("There should exist an error") + } } func TestParsePVCSpec(t *testing.T) { @@ -144,8 +177,12 @@ func TestParsePVCSpec(t *testing.T) { StorageClassName: &storageClassName, } result, err := ParsePVCSpec(pvcSpec) - assert.NoError(t, err) - assert.Equal(t, expectedSpec, *result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedSpec, *result) { + t.Errorf("got %+v, want %+v", *result, expectedSpec) + } // Test case 2: Invalid PVC spec invalidSpec := `{ @@ -158,7 +195,9 @@ func TestParsePVCSpec(t *testing.T) { "storageClassName": "standard_1" }` _, err = ParsePVCSpec(invalidSpec) - assert.Error(t, err) + if err == nil { + t.Errorf("There should exist an error") + } } func TestParsePVandPVCSpec(t *testing.T) { @@ -203,10 +242,15 @@ func TestParsePVandPVCSpec(t *testing.T) { StorageClassName: &storageClassName, } pvSpec, pvcSpec, err := ParsePVandPVCSpec(jsonStr) - assert.NoError(t, err) - assert.Equal(t, expectedPVSpec, *pvSpec) - assert.Equal(t, expectedPVCSpec, *pvcSpec) - + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedPVSpec, *pvSpec) { + t.Errorf("got %+v, want %+v", *pvSpec, expectedPVSpec) + } + if !reflect.DeepEqual(expectedPVCSpec, *pvcSpec) { + t.Errorf("got %+v, want %+v", *pvcSpec, expectedPVCSpec) + } } func TestGetPVAndPVC(t *testing.T) { @@ -251,17 +295,28 @@ func TestGetPVAndPVC(t *testing.T) { StorageClassName: &storageClassName, } pvSpec, pvcSpec, err := GetPVAndPVC(pvAndPVC) - assert.NoError(t, err) - assert.Equal(t, expectedPVSpec, *pvSpec) - assert.Equal(t, expectedPVCSpec, *pvcSpec) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedPVSpec, *pvSpec) { + t.Errorf("got %+v, want %+v", *pvSpec, expectedPVSpec) + } + if !reflect.DeepEqual(expectedPVCSpec, *pvcSpec) { + t.Errorf("got %+v, want %+v", *pvcSpec, expectedPVCSpec) + } // Test case 2: Empty input emptyInput := "" pvSpec, pvcSpec, err = GetPVAndPVC(emptyInput) - assert.NoError(t, err) - assert.Nil(t, pvSpec) - assert.Nil(t, pvcSpec) - + if err != nil { + t.Errorf("Error: %d", err) + } + if pvSpec != nil { + t.Errorf("pvSpec should be nil") + } + if pvcSpec != nil { + t.Errorf("pvcSpec should be nil") + } } func TestParseOwnerRef(t *testing.T) { @@ -285,19 +340,29 @@ func TestParseOwnerRef(t *testing.T) { }, } result, err := ParseOwnerRef(ownerRefJSON) - assert.NoError(t, err) - assert.Equal(t, expectedOwnerRef, result) + if err != nil { + t.Errorf("Error: %d", err) + } + if !reflect.DeepEqual(expectedOwnerRef, result) { + t.Errorf("got %+v, want %+v", result, expectedOwnerRef) + } // Test case 2: Empty input emptyInput := "" result, err = ParseOwnerRef(emptyInput) - assert.NoError(t, err) - assert.Empty(t, result) + if err != nil { + t.Errorf("Error: %d", err) + } + if len(result) != 0 { + t.Errorf("result should be nil") + } // Test case 3: Invalid input invalidInput := `{"apiVersion": "v1", "kind": "Pod", "name": "my-pod"}` _, err = ParseOwnerRef(invalidInput) - assert.Error(t, err) + if err == nil { + t.Errorf("There should exist an error") + } } // Helper function to return pointer to a boolean value diff --git a/k8s/cmd/commands/util/template_test.go b/k8s/cmd/commands/util/template_test.go index b0800e28..7746870f 100644 --- a/k8s/cmd/commands/util/template_test.go +++ b/k8s/cmd/commands/util/template_test.go @@ -21,7 +21,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -160,8 +159,10 @@ func TestBuildObjsFromEtcdManifests(t *testing.T) { image := vineyardd.Spec.Vineyard.Image podObjs, svcObjs, err := BuildObjsFromEtcdManifests(&etcdConfig, name, namespace, replicas, image, value, tmplFunc) + if err != nil { + t.Errorf("Error: %d", err) + } - assert.NoError(t, err) if len(podObjs) != 10 { t.Errorf("Expected %d objects, but got %d", 10, len(podObjs)) } @@ -275,7 +276,9 @@ func TestBuildObjsFromManifests(t *testing.T) { objs, err := BuildObjsFromManifests(templateName, backup, tmplFunc) - assert.NoError(t, err) + if err != nil { + t.Errorf("Error: %d", err) + } if len(objs) != 4 { t.Errorf("Expected %d objects, but got %d", 4, len(objs)) } diff --git a/k8s/cmd/commands/util/usage/md_docs.go b/k8s/cmd/commands/util/usage/md_docs.go index 886c0837..63baa7c4 100644 --- a/k8s/cmd/commands/util/usage/md_docs.go +++ b/k8s/cmd/commands/util/usage/md_docs.go @@ -66,11 +66,6 @@ func printOptions(buf *bytes.Buffer, titleLevel string, cmd *cobra.Command, name return nil } -// GenMarkdown creates markdown output. -func GenMarkdown(cmd *cobra.Command, w io.Writer) error { - return GenMarkdownCustom(cmd, w, func(s string) string { return s }) -} - // GenMarkdownCustom creates custom markdown output. func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error { cmd.InitDefaultHelpCmd() diff --git a/k8s/go.mod b/k8s/go.mod index 8074bdd0..bd4efc42 100644 --- a/k8s/go.mod +++ b/k8s/go.mod @@ -15,7 +15,6 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 - github.com/stretchr/testify v1.8.0 github.com/v6d-io/v6d/go/vineyard v0.0.0-00010101000000-000000000000 go.uber.org/multierr v1.9.0 go.uber.org/zap v1.24.0 @@ -88,7 +87,6 @@ require ( github.com/nxadm/tail v1.4.8 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/selinux v1.10.0 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect From 3038f1ac08012e4bfd14aafed775a3b5fea3fc27 Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Tue, 12 Sep 2023 15:43:08 +0800 Subject: [PATCH 2/7] Revert changes in vineyardctl unit-tests Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/cmd/commands/util/manifests_test.go | 34 ++---- k8s/cmd/commands/util/parse_test.go | 145 +++++++----------------- k8s/cmd/commands/util/template_test.go | 9 +- k8s/go.mod | 2 + 4 files changed, 55 insertions(+), 135 deletions(-) diff --git a/k8s/cmd/commands/util/manifests_test.go b/k8s/cmd/commands/util/manifests_test.go index 2d17fd99..573a13d7 100644 --- a/k8s/cmd/commands/util/manifests_test.go +++ b/k8s/cmd/commands/util/manifests_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/controller-runtime/pkg/client" @@ -216,9 +217,8 @@ func Test_ApplyManifests(t *testing.T) { pod.SetKind("Pod") pod.SetAPIVersion("v1") err := c.Get(context.Background(), client.ObjectKey{Name: "my-pod-1", Namespace: "vineyard-system"}, pod) - if err != nil { - t.Errorf("Error: %d", err) - } + assert.Nil(t, err) + } } @@ -279,9 +279,7 @@ func Test_DeleteManifests(t *testing.T) { pod.SetKind("Pod") pod.SetAPIVersion("v1") err := c.Get(context.Background(), client.ObjectKey{Name: "my-pod-1", Namespace: "vineyard-system"}, pod) - if err == nil { - t.Errorf("There should exist an error") - } + assert.NotNil(t, err) } } @@ -494,9 +492,7 @@ func Test_ApplyManifestsWithOwnerRef(t *testing.T) { // Test with valid inputs err := ApplyManifestsWithOwnerRef(c, objs, "Job", "Role,Rolebinding") - if err != nil { - t.Errorf("Error: %d", err) - } + assert.Nil(t, err) // Check if OwnerReference was set for "Role" kind RoleBinding := &unstructured.Unstructured{} @@ -504,24 +500,14 @@ func Test_ApplyManifestsWithOwnerRef(t *testing.T) { RoleBinding.SetAPIVersion("rbac.authorization.k8s.io/v1") err = c.Get(context.Background(), client.ObjectKey{Name: "vineyard-backup", Namespace: "vineyard-system"}, RoleBinding) - if err != nil { - t.Errorf("Error: %d", err) - } + assert.Nil(t, err) time.Sleep(2 * time.Second) ownerRefs := RoleBinding.GetOwnerReferences() - if !reflect.DeepEqual(1, len(ownerRefs)) { - t.Errorf("got %+v, want %+v", len(ownerRefs), 1) - } - if !reflect.DeepEqual("Job", ownerRefs[0].Kind) { - t.Errorf("got %+v, want %+v", ownerRefs[0].Kind, "Job") - } - if !reflect.DeepEqual("vineyard-backup", ownerRefs[0].Name) { - t.Errorf("got %+v, want %+v", ownerRefs[0].Name, "vineyard-backup") - } + assert.Equal(t, 1, len(ownerRefs)) + assert.Equal(t, "Job", ownerRefs[0].Kind) + assert.Equal(t, "vineyard-backup", ownerRefs[0].Name) // Test with unsupported kind in refKind err = ApplyManifestsWithOwnerRef(c, objs, "Job", "Unsupported") - if err != nil { - t.Errorf("Error: %d", err) - } + assert.Nil(t, err) } diff --git a/k8s/cmd/commands/util/parse_test.go b/k8s/cmd/commands/util/parse_test.go index c15abfb4..5670f53a 100644 --- a/k8s/cmd/commands/util/parse_test.go +++ b/k8s/cmd/commands/util/parse_test.go @@ -16,9 +16,9 @@ limitations under the License. package util import ( - "reflect" "testing" + "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -27,28 +27,20 @@ import ( func TestConvertToJson(t *testing.T) { // Test case 1: Valid JSON input jsonStr := `{"name":"John", "age": 31}` - expectedJSON := `{"name":"John", "age": 31}` + expectedJSON := `{"name":"John","age":31}` result, err := ConvertToJson(jsonStr) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedJSON, result) { - t.Errorf("got %+v, want %+v", result, expectedJSON) - } + assert.NoError(t, err) + assert.JSONEq(t, expectedJSON, result) // Test case 2: Valid YAML input yamlStr := ` name: John age: 32 ` - expectedYAML := `{"age":32,"name":"John"}` + expectedYAML := `{"name":"John","age":32}` result, err = ConvertToJson(yamlStr) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedYAML, result) { - t.Errorf("got %+v, want %+v", result, expectedYAML) - } + assert.NoError(t, err) + assert.JSONEq(t, expectedYAML, result) } @@ -59,12 +51,9 @@ func TestConvertToYaml(t *testing.T) { name: John ` result, err := ConvertToYaml(jsonStr) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedYAML, result) { - t.Errorf("got %+v, want %+v", result, expectedYAML) - } + assert.NoError(t, err) + assert.Equal(t, expectedYAML, result) + } func TestParseEnvs(t *testing.T) { @@ -75,42 +64,26 @@ func TestParseEnvs(t *testing.T) { {Name: "KEY2=Value2", Value: "KEY2=Value2"}, } result, err := ParseEnvs(envArray) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedEnvs, result) { - t.Errorf("got %+v, want %+v", result, expectedEnvs) - } + assert.NoError(t, err) + assert.Equal(t, expectedEnvs, result) // Test case 2: Invalid env string without "=" separator invalidEnv := []string{"KEY1:Value1"} _, err = ParseEnvs(invalidEnv) - if err == nil { - t.Errorf("There should exist an error") - } - if !reflect.DeepEqual(err.Error(), "invalid env string") { - t.Errorf("got wrong err: %+v", err) - } + assert.Error(t, err) + assert.EqualError(t, err, "invalid env string") // Test case 3: Invalid env with empty name emptyNameEnv := []string{"=Value1"} _, err = ParseEnvs(emptyNameEnv) - if err == nil { - t.Errorf("There should exist an error") - } - if !reflect.DeepEqual(err.Error(), "the name of env can not be empty") { - t.Errorf("got wrong err: %+v", err) - } + assert.Error(t, err) + assert.EqualError(t, err, "the name of env can not be empty") // Test case 4: Invalid env with empty value emptyValueEnv := []string{"KEY1="} _, err = ParseEnvs(emptyValueEnv) - if err == nil { - t.Errorf("There should exist an error") - } - if !reflect.DeepEqual(err.Error(), "the value of env can not be empty") { - t.Errorf("got wrong err: %+v", err) - } + assert.Error(t, err) + assert.EqualError(t, err, "the value of env can not be empty") } func TestParsePVSpec(t *testing.T) { @@ -132,12 +105,8 @@ func TestParsePVSpec(t *testing.T) { PersistentVolumeReclaimPolicy: corev1.PersistentVolumeReclaimRetain, } result, err := ParsePVSpec(pvSpec) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedSpec, *result) { - t.Errorf("got %+v, want %+v", *result, expectedSpec) - } + assert.NoError(t, err) + assert.Equal(t, expectedSpec, *result) // Test case 2: Invalid PV spec invalidSpec := `{ @@ -148,9 +117,7 @@ func TestParsePVSpec(t *testing.T) { "persistentVolumeReclaimPolicy": "Retain" }` _, err = ParsePVSpec(invalidSpec) - if err == nil { - t.Errorf("There should exist an error") - } + assert.Error(t, err) } func TestParsePVCSpec(t *testing.T) { @@ -177,12 +144,8 @@ func TestParsePVCSpec(t *testing.T) { StorageClassName: &storageClassName, } result, err := ParsePVCSpec(pvcSpec) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedSpec, *result) { - t.Errorf("got %+v, want %+v", *result, expectedSpec) - } + assert.NoError(t, err) + assert.Equal(t, expectedSpec, *result) // Test case 2: Invalid PVC spec invalidSpec := `{ @@ -195,9 +158,7 @@ func TestParsePVCSpec(t *testing.T) { "storageClassName": "standard_1" }` _, err = ParsePVCSpec(invalidSpec) - if err == nil { - t.Errorf("There should exist an error") - } + assert.Error(t, err) } func TestParsePVandPVCSpec(t *testing.T) { @@ -242,15 +203,10 @@ func TestParsePVandPVCSpec(t *testing.T) { StorageClassName: &storageClassName, } pvSpec, pvcSpec, err := ParsePVandPVCSpec(jsonStr) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedPVSpec, *pvSpec) { - t.Errorf("got %+v, want %+v", *pvSpec, expectedPVSpec) - } - if !reflect.DeepEqual(expectedPVCSpec, *pvcSpec) { - t.Errorf("got %+v, want %+v", *pvcSpec, expectedPVCSpec) - } + assert.NoError(t, err) + assert.Equal(t, expectedPVSpec, *pvSpec) + assert.Equal(t, expectedPVCSpec, *pvcSpec) + } func TestGetPVAndPVC(t *testing.T) { @@ -295,28 +251,17 @@ func TestGetPVAndPVC(t *testing.T) { StorageClassName: &storageClassName, } pvSpec, pvcSpec, err := GetPVAndPVC(pvAndPVC) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedPVSpec, *pvSpec) { - t.Errorf("got %+v, want %+v", *pvSpec, expectedPVSpec) - } - if !reflect.DeepEqual(expectedPVCSpec, *pvcSpec) { - t.Errorf("got %+v, want %+v", *pvcSpec, expectedPVCSpec) - } + assert.NoError(t, err) + assert.Equal(t, expectedPVSpec, *pvSpec) + assert.Equal(t, expectedPVCSpec, *pvcSpec) // Test case 2: Empty input emptyInput := "" pvSpec, pvcSpec, err = GetPVAndPVC(emptyInput) - if err != nil { - t.Errorf("Error: %d", err) - } - if pvSpec != nil { - t.Errorf("pvSpec should be nil") - } - if pvcSpec != nil { - t.Errorf("pvcSpec should be nil") - } + assert.NoError(t, err) + assert.Nil(t, pvSpec) + assert.Nil(t, pvcSpec) + } func TestParseOwnerRef(t *testing.T) { @@ -340,29 +285,19 @@ func TestParseOwnerRef(t *testing.T) { }, } result, err := ParseOwnerRef(ownerRefJSON) - if err != nil { - t.Errorf("Error: %d", err) - } - if !reflect.DeepEqual(expectedOwnerRef, result) { - t.Errorf("got %+v, want %+v", result, expectedOwnerRef) - } + assert.NoError(t, err) + assert.Equal(t, expectedOwnerRef, result) // Test case 2: Empty input emptyInput := "" result, err = ParseOwnerRef(emptyInput) - if err != nil { - t.Errorf("Error: %d", err) - } - if len(result) != 0 { - t.Errorf("result should be nil") - } + assert.NoError(t, err) + assert.Empty(t, result) // Test case 3: Invalid input invalidInput := `{"apiVersion": "v1", "kind": "Pod", "name": "my-pod"}` _, err = ParseOwnerRef(invalidInput) - if err == nil { - t.Errorf("There should exist an error") - } + assert.Error(t, err) } // Helper function to return pointer to a boolean value diff --git a/k8s/cmd/commands/util/template_test.go b/k8s/cmd/commands/util/template_test.go index 7746870f..b0800e28 100644 --- a/k8s/cmd/commands/util/template_test.go +++ b/k8s/cmd/commands/util/template_test.go @@ -21,6 +21,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -159,10 +160,8 @@ func TestBuildObjsFromEtcdManifests(t *testing.T) { image := vineyardd.Spec.Vineyard.Image podObjs, svcObjs, err := BuildObjsFromEtcdManifests(&etcdConfig, name, namespace, replicas, image, value, tmplFunc) - if err != nil { - t.Errorf("Error: %d", err) - } + assert.NoError(t, err) if len(podObjs) != 10 { t.Errorf("Expected %d objects, but got %d", 10, len(podObjs)) } @@ -276,9 +275,7 @@ func TestBuildObjsFromManifests(t *testing.T) { objs, err := BuildObjsFromManifests(templateName, backup, tmplFunc) - if err != nil { - t.Errorf("Error: %d", err) - } + assert.NoError(t, err) if len(objs) != 4 { t.Errorf("Expected %d objects, but got %d", 4, len(objs)) } diff --git a/k8s/go.mod b/k8s/go.mod index bd4efc42..8074bdd0 100644 --- a/k8s/go.mod +++ b/k8s/go.mod @@ -15,6 +15,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 + github.com/stretchr/testify v1.8.0 github.com/v6d-io/v6d/go/vineyard v0.0.0-00010101000000-000000000000 go.uber.org/multierr v1.9.0 go.uber.org/zap v1.24.0 @@ -87,6 +88,7 @@ require ( github.com/nxadm/tail v1.4.8 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/selinux v1.10.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_golang v1.12.2 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.32.1 // indirect From 06d381e85d6b9df6484bd1ff0a189353dce9f308 Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Tue, 12 Sep 2023 20:52:48 +0800 Subject: [PATCH 3/7] prune dependency github.com/onsi/ginkgo Signed-off-by: zhuyi1159 <1159751291@qq.com> --- ...{webhook_suite_test.go => webhook_test.go} | 58 +++++++++---------- .../k8s/{suite_test.go => controller_test.go} | 37 +++++------- k8s/go.mod | 4 -- 3 files changed, 43 insertions(+), 56 deletions(-) rename k8s/apis/k8s/v1alpha1/{webhook_suite_test.go => webhook_test.go} (79%) rename k8s/controllers/k8s/{suite_test.go => controller_test.go} (77%) diff --git a/k8s/apis/k8s/v1alpha1/webhook_suite_test.go b/k8s/apis/k8s/v1alpha1/webhook_test.go similarity index 79% rename from k8s/apis/k8s/v1alpha1/webhook_suite_test.go rename to k8s/apis/k8s/v1alpha1/webhook_test.go index af8e64ee..3036f16c 100644 --- a/k8s/apis/k8s/v1alpha1/webhook_suite_test.go +++ b/k8s/apis/k8s/v1alpha1/webhook_test.go @@ -16,13 +16,15 @@ import ( "context" "crypto/tls" "fmt" + "io" "net" "path/filepath" "testing" "time" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/avast/retry-go" + "github.com/stretchr/testify/assert" + "github.com/v6d-io/v6d/k8s/pkg/log" admissionv1beta1 "k8s.io/api/admission/v1beta1" //+kubebuilder:scaffold:imports @@ -47,19 +49,13 @@ var ( cancel context.CancelFunc ) -func TestAPIs(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecs(t, - "Webhook Suite") -} - -var _ = BeforeSuite(func() { +func Test_BeforeSuite(t *testing.T) { + var GinkgoWriter io.Writer logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) ctx, cancel = context.WithCancel(context.TODO()) - By("bootstrapping test environment") + log.Info("Bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, ErrorIfCRDPathMissing: false, @@ -71,21 +67,21 @@ var _ = BeforeSuite(func() { var err error // cfg is defined in this file globally. cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) + assert.NoError(t, err) + assert.NotNil(t, cfg) scheme := runtime.NewScheme() err = AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) err = admissionv1beta1.AddToScheme(scheme) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) //+kubebuilder:scaffold:scheme k8sClient, err = client.New(cfg, client.Options{Scheme: scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) + assert.NoError(t, err) + assert.NotNil(t, k8sClient) // start webhook server using Manager webhookInstallOptions := &testEnv.WebhookInstallOptions @@ -97,26 +93,25 @@ var _ = BeforeSuite(func() { LeaderElection: false, MetricsBindAddress: "0", }) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) err = (&Operation{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) err = (&Sidecar{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) err = (&Backup{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) err = (&Recover{}).SetupWebhookWithManager(mgr) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) //+kubebuilder:scaffold:webhook go func() { - defer GinkgoRecover() err = mgr.Start(ctx) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) }() // wait for the webhook server to get ready @@ -126,7 +121,7 @@ var _ = BeforeSuite(func() { webhookInstallOptions.LocalServingHost, webhookInstallOptions.LocalServingPort, ) - Eventually(func() error { + err = retry.Do(func() error { conn, err := tls.DialWithDialer( dialer, "tcp", @@ -138,12 +133,13 @@ var _ = BeforeSuite(func() { } conn.Close() return nil - }).Should(Succeed()) -}, 60) + }) + assert.NoError(t, err) +} -var _ = AfterSuite(func() { +func Test_AfterSuite(t *testing.T) { cancel() - By("tearing down the test environment") + log.Info("tearing down the test environment") err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) -}) + assert.NoError(t, err) +} diff --git a/k8s/controllers/k8s/suite_test.go b/k8s/controllers/k8s/controller_test.go similarity index 77% rename from k8s/controllers/k8s/suite_test.go rename to k8s/controllers/k8s/controller_test.go index 57f8c18f..05915ca7 100644 --- a/k8s/controllers/k8s/suite_test.go +++ b/k8s/controllers/k8s/controller_test.go @@ -13,11 +13,11 @@ limitations under the License. package k8s import ( + "io" "path/filepath" "testing" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + "github.com/stretchr/testify/assert" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "sigs.k8s.io/controller-runtime/pkg/client" @@ -27,6 +27,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/log/zap" k8sv1alpha1 "github.com/v6d-io/v6d/k8s/apis/k8s/v1alpha1" + "github.com/v6d-io/v6d/k8s/pkg/log" //+kubebuilder:scaffold:imports ) @@ -37,16 +38,11 @@ var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment -func TestAPIs(t *testing.T) { - RegisterFailHandler(Fail) - - RunSpecs(t, "Controller Suite") -} - -var _ = BeforeSuite(func() { +func Test_BeforeSuite(t *testing.T) { + var GinkgoWriter io.Writer logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - By("bootstrapping test environment") + log.Info("Bootstrapping test environment") testEnv = &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, ErrorIfCRDPathMissing: true, @@ -55,22 +51,21 @@ var _ = BeforeSuite(func() { var err error // cfg is defined in this file globally. cfg, err = testEnv.Start() - Expect(err).NotTo(HaveOccurred()) - Expect(cfg).NotTo(BeNil()) + assert.NoError(t, err) + assert.NotNil(t, cfg) err = k8sv1alpha1.AddToScheme(scheme.Scheme) - Expect(err).NotTo(HaveOccurred()) + assert.NoError(t, err) //+kubebuilder:scaffold:scheme k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) - Expect(err).NotTo(HaveOccurred()) - Expect(k8sClient).NotTo(BeNil()) - -}, 60) + assert.NoError(t, err) + assert.NotNil(t, k8sClient) +} -var _ = AfterSuite(func() { - By("tearing down the test environment") +func Test_AfterSuite(t *testing.T) { + log.Info("tearing down the test environment") err := testEnv.Stop() - Expect(err).NotTo(HaveOccurred()) -}) + assert.NoError(t, err) +} diff --git a/k8s/go.mod b/k8s/go.mod index 8074bdd0..01935d1d 100644 --- a/k8s/go.mod +++ b/k8s/go.mod @@ -10,8 +10,6 @@ require ( github.com/ghodss/yaml v1.0.0 github.com/go-logr/logr v1.2.3 github.com/olekukonko/tablewriter v0.0.4 - github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.20.1 github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.4.0 github.com/spf13/pflag v1.0.5 @@ -85,7 +83,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/nxadm/tail v1.4.8 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/selinux v1.10.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -129,7 +126,6 @@ require ( google.golang.org/protobuf v1.28.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect - gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/apiserver v0.25.10 // indirect From 0f9a08eb41939f9f9678e0f30eee4e11a0ec00a7 Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Thu, 14 Sep 2023 14:28:59 +0800 Subject: [PATCH 4/7] refactor webhook_test.go and controller_test.go Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/apis/k8s/v1alpha1/webhook_test.go | 9 +++---- k8s/config/webhook/manifests.yaml | 34 +++++++++++++------------- k8s/controllers/k8s/controller_test.go | 6 ++--- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/k8s/apis/k8s/v1alpha1/webhook_test.go b/k8s/apis/k8s/v1alpha1/webhook_test.go index 3036f16c..c526409c 100644 --- a/k8s/apis/k8s/v1alpha1/webhook_test.go +++ b/k8s/apis/k8s/v1alpha1/webhook_test.go @@ -49,7 +49,7 @@ var ( cancel context.CancelFunc ) -func Test_BeforeSuite(t *testing.T) { +func Test_webhook(t *testing.T) { var GinkgoWriter io.Writer logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) @@ -60,7 +60,7 @@ func Test_BeforeSuite(t *testing.T) { CRDDirectoryPaths: []string{filepath.Join("..", "..", "..", "config", "crd", "bases")}, ErrorIfCRDPathMissing: false, WebhookInstallOptions: envtest.WebhookInstallOptions{ - Paths: []string{filepath.Join("..", "..", "..", "config", "webhook")}, + Paths: []string{filepath.Join("..", "..", "..", "config", "webhook", "manifests.yaml")}, }, } @@ -135,11 +135,10 @@ func Test_BeforeSuite(t *testing.T) { return nil }) assert.NoError(t, err) -} -func Test_AfterSuite(t *testing.T) { + time.Sleep(1 * time.Second) cancel() log.Info("tearing down the test environment") - err := testEnv.Stop() + err = testEnv.Stop() assert.NoError(t, err) } diff --git a/k8s/config/webhook/manifests.yaml b/k8s/config/webhook/manifests.yaml index ff88f70e..63abe983 100644 --- a/k8s/config/webhook/manifests.yaml +++ b/k8s/config/webhook/manifests.yaml @@ -6,7 +6,7 @@ metadata: name: mutating-webhook-configuration webhooks: - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -26,7 +26,7 @@ webhooks: - backups sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -46,7 +46,7 @@ webhooks: - globalobjects sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -66,7 +66,7 @@ webhooks: - localobjects sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -86,7 +86,7 @@ webhooks: - operations sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -106,7 +106,7 @@ webhooks: - recovers sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -126,7 +126,7 @@ webhooks: - sidecars sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -146,7 +146,7 @@ webhooks: - vineyardds sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -166,7 +166,7 @@ webhooks: - pods sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -185,7 +185,7 @@ webhooks: - pods sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -212,7 +212,7 @@ metadata: name: validating-webhook-configuration webhooks: - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -232,7 +232,7 @@ webhooks: - backups sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -252,7 +252,7 @@ webhooks: - globalobjects sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -272,7 +272,7 @@ webhooks: - localobjects sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -292,7 +292,7 @@ webhooks: - operations sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -312,7 +312,7 @@ webhooks: - recovers sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service @@ -332,7 +332,7 @@ webhooks: - sidecars sideEffects: None - admissionReviewVersions: - - v1 + - v1beta1 clientConfig: service: name: webhook-service diff --git a/k8s/controllers/k8s/controller_test.go b/k8s/controllers/k8s/controller_test.go index 05915ca7..153d3b09 100644 --- a/k8s/controllers/k8s/controller_test.go +++ b/k8s/controllers/k8s/controller_test.go @@ -16,6 +16,7 @@ import ( "io" "path/filepath" "testing" + "time" "github.com/stretchr/testify/assert" "k8s.io/client-go/kubernetes/scheme" @@ -62,10 +63,9 @@ func Test_BeforeSuite(t *testing.T) { k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme}) assert.NoError(t, err) assert.NotNil(t, k8sClient) -} -func Test_AfterSuite(t *testing.T) { + time.Sleep(1 * time.Second) log.Info("tearing down the test environment") - err := testEnv.Stop() + err = testEnv.Stop() assert.NoError(t, err) } From f4448948051a8e82aff0ca1617a804989bb63561 Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Thu, 14 Sep 2023 16:51:06 +0800 Subject: [PATCH 5/7] revert changes in k8s/config/webhook/manifests.yaml Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/config/webhook/manifests.yaml | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/k8s/config/webhook/manifests.yaml b/k8s/config/webhook/manifests.yaml index 63abe983..ff88f70e 100644 --- a/k8s/config/webhook/manifests.yaml +++ b/k8s/config/webhook/manifests.yaml @@ -6,7 +6,7 @@ metadata: name: mutating-webhook-configuration webhooks: - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -26,7 +26,7 @@ webhooks: - backups sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -46,7 +46,7 @@ webhooks: - globalobjects sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -66,7 +66,7 @@ webhooks: - localobjects sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -86,7 +86,7 @@ webhooks: - operations sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -106,7 +106,7 @@ webhooks: - recovers sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -126,7 +126,7 @@ webhooks: - sidecars sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -146,7 +146,7 @@ webhooks: - vineyardds sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -166,7 +166,7 @@ webhooks: - pods sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -185,7 +185,7 @@ webhooks: - pods sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -212,7 +212,7 @@ metadata: name: validating-webhook-configuration webhooks: - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -232,7 +232,7 @@ webhooks: - backups sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -252,7 +252,7 @@ webhooks: - globalobjects sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -272,7 +272,7 @@ webhooks: - localobjects sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -292,7 +292,7 @@ webhooks: - operations sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -312,7 +312,7 @@ webhooks: - recovers sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service @@ -332,7 +332,7 @@ webhooks: - sidecars sideEffects: None - admissionReviewVersions: - - v1beta1 + - v1 clientConfig: service: name: webhook-service From be7cfe6094932c61e64601c30e1b63095485c00c Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Thu, 14 Sep 2023 16:55:10 +0800 Subject: [PATCH 6/7] refactor controller_test.go Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/controllers/k8s/controller_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/controllers/k8s/controller_test.go b/k8s/controllers/k8s/controller_test.go index 153d3b09..5a9423ba 100644 --- a/k8s/controllers/k8s/controller_test.go +++ b/k8s/controllers/k8s/controller_test.go @@ -39,7 +39,7 @@ var cfg *rest.Config var k8sClient client.Client var testEnv *envtest.Environment -func Test_BeforeSuite(t *testing.T) { +func Test_controller(t *testing.T) { var GinkgoWriter io.Writer logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) From 74f94dc74a5a56626ede4e7aa3adfb473e38b678 Mon Sep 17 00:00:00 2001 From: zhuyi1159 <1159751291@qq.com> Date: Fri, 15 Sep 2023 14:11:15 +0800 Subject: [PATCH 7/7] refactor webhook_test.go Signed-off-by: zhuyi1159 <1159751291@qq.com> --- k8s/apis/k8s/v1alpha1/webhook_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/k8s/apis/k8s/v1alpha1/webhook_test.go b/k8s/apis/k8s/v1alpha1/webhook_test.go index c526409c..cd9bb277 100644 --- a/k8s/apis/k8s/v1alpha1/webhook_test.go +++ b/k8s/apis/k8s/v1alpha1/webhook_test.go @@ -136,8 +136,8 @@ func Test_webhook(t *testing.T) { }) assert.NoError(t, err) - time.Sleep(1 * time.Second) cancel() + time.Sleep(1 * time.Second) log.Info("tearing down the test environment") err = testEnv.Stop() assert.NoError(t, err)