Skip to content

Commit

Permalink
*: update kvproto (#8816)
Browse files Browse the repository at this point in the history
ref #4399, ref pingcap/tidb#57338

Signed-off-by: Neil Shen <[email protected]>
  • Loading branch information
overvenus authored Nov 22, 2024
1 parent 90cc61b commit 2917d45
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions pkg/mcs/resourcemanager/server/resource_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package server

import (
"encoding/json"
"reflect"
"testing"

"github.com/brianvoe/gofakeit/v6"
Expand Down Expand Up @@ -37,37 +36,10 @@ func TestPatchResourceGroup(t *testing.T) {
}
}

func resetSizeCache(obj any) {
resetSizeCacheRecursive(reflect.ValueOf(obj))
}

func resetSizeCacheRecursive(value reflect.Value) {
if value.Kind() == reflect.Ptr {
value = value.Elem()
}

if value.Kind() != reflect.Struct {
return
}

for i := range value.NumField() {
fieldValue := value.Field(i)
fieldType := value.Type().Field(i)

if fieldType.Name == "XXX_sizecache" && fieldType.Type.Kind() == reflect.Int32 {
fieldValue.SetInt(0)
} else {
resetSizeCacheRecursive(fieldValue)
}
}
}

func TestClone(t *testing.T) {
for i := 0; i <= 10; i++ {
var rg ResourceGroup
gofakeit.Struct(&rg)
// hack to reset XXX_sizecache, gofakeit will random set this field but proto clone will not copy this field.
resetSizeCache(&rg)
rgClone := rg.Clone(true)
require.EqualValues(t, &rg, rgClone)
}
Expand Down

0 comments on commit 2917d45

Please sign in to comment.