@@ -18,6 +18,7 @@ import (
1818 "testing"
1919
2020 "github.com/stretchr/testify/assert"
21+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
2223 "github.com/pingcap/tidb-operator/api/v2/core/v1alpha1"
2324 metav1alpha1 "github.com/pingcap/tidb-operator/api/v2/meta/v1alpha1"
@@ -300,3 +301,49 @@ func TestCondFeatureGatesIsNotSynced(t *testing.T) {
300301 })
301302 }
302303}
304+
305+ func TestCondObjectIsNotDeletingButOfflined (t * testing.T ) {
306+ cases := []struct {
307+ desc string
308+ state ObjectState [* v1alpha1.TiKV ]
309+ expectedCond bool
310+ }{
311+ {
312+ desc : "cond is false, not offlined" ,
313+ state : newFakeObjectState (
314+ fake.FakeObj [v1alpha1.TiKV ]("test" ),
315+ ),
316+ },
317+ {
318+ desc : "cond is false, deleting" ,
319+ state : newFakeObjectState (
320+ fake .FakeObj ("test" , fake .DeleteNow [v1alpha1.TiKV ]()),
321+ ),
322+ },
323+ {
324+ desc : "cond is true" ,
325+ state : newFakeObjectState (
326+ fake .FakeObj ("test" , func (obj * v1alpha1.TiKV ) * v1alpha1.TiKV {
327+ obj .Status .Conditions = []metav1.Condition {
328+ {
329+ Type : v1alpha1 .StoreOfflinedConditionType ,
330+ Status : metav1 .ConditionTrue ,
331+ },
332+ }
333+ return obj
334+ }),
335+ ),
336+ expectedCond : true ,
337+ },
338+ }
339+
340+ for i := range cases {
341+ c := & cases [i ]
342+ t .Run (c .desc , func (tt * testing.T ) {
343+ tt .Parallel ()
344+
345+ cond := CondObjectIsNotDeletingButOfflined [scope.TiKV ](c .state )
346+ assert .Equal (tt , c .expectedCond , cond .Satisfy (), c .desc )
347+ })
348+ }
349+ }
0 commit comments