Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
修改单测名称
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-657667 committed Sep 5, 2023
1 parent 08e7949 commit a52d5b7
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions module-controller/internal/utils/controller_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"github.com/sofastack/sofa-serverless/internal/constants/finalizer"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -9,27 +10,40 @@ import (
"time"
)

const (
ExistingModuleReplicaSetFinalizer = "existing-module-replicaset"
)
func TestAddNotExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
assert.True(t, AddFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestHasNotExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
assert.False(t, HasFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestRemoveNotExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
assert.False(t, RemoveFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestAddExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
meta.Finalizers = []string{finalizer.ModuleReplicaSetExistedFinalizer}
assert.False(t, AddFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestFinalizerFunTrue(t *testing.T) {
func TestHasExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
assert.True(t, AddFinalizer(meta, ExistingModuleReplicaSetFinalizer))
assert.True(t, HasFinalizer(meta, ExistingModuleReplicaSetFinalizer))
assert.True(t, RemoveFinalizer(meta, ExistingModuleReplicaSetFinalizer))
meta.Finalizers = []string{finalizer.ModuleReplicaSetExistedFinalizer}
assert.True(t, HasFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestFinalizerFunFalse(t *testing.T) {
func TestRemoveExistedFinalizer(t *testing.T) {
meta := &metav1.ObjectMeta{}
meta.Finalizers = []string{ExistingModuleReplicaSetFinalizer}
assert.False(t, AddFinalizer(meta, ExistingModuleReplicaSetFinalizer))
assert.False(t, RemoveFinalizer(meta, "test"))
RemoveFinalizer(meta, ExistingModuleReplicaSetFinalizer)
assert.False(t, HasFinalizer(meta, ExistingModuleReplicaSetFinalizer))
meta.Finalizers = []string{finalizer.ModuleReplicaSetExistedFinalizer}
assert.True(t, RemoveFinalizer(meta, finalizer.ModuleReplicaSetExistedFinalizer))
}

func TestKeyFun(t *testing.T) {
func TestKeyEqual(t *testing.T) {
request := ctrl.Request{NamespacedName: types.NamespacedName{Namespace: "default", Name: "test"}}
key := Key(request)
assert.Equal(t, "default/test", key)
Expand Down

0 comments on commit a52d5b7

Please sign in to comment.