forked from mirror/gorm
test: add test for LoadOrStoreVisitMap
This commit is contained in:
parent
9d5c68e410
commit
6e3ca2d1aa
|
@ -2,12 +2,13 @@ package tests_test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/callbacks"
|
||||
. "gorm.io/gorm/utils/tests"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func assertCallbacks(v interface{}, fnames []string) (result bool, msg string) {
|
||||
|
@ -168,3 +169,26 @@ func TestCallbacks(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadOrStoreVisitMap(t *testing.T) {
|
||||
var vistMap callbacks.VisitMap
|
||||
var loaded bool
|
||||
|
||||
type testM struct {
|
||||
Name string
|
||||
}
|
||||
t1 := testM{Name: "t1"}
|
||||
t2 := testM{Name: "t2"}
|
||||
t3 := testM{Name: "t3"}
|
||||
|
||||
vistMap = make(callbacks.VisitMap)
|
||||
loaded = callbacks.LoadOrStoreVisitMap(&vistMap, &t1)
|
||||
AssertEqual(t, loaded, false)
|
||||
loaded = callbacks.LoadOrStoreVisitMap(&vistMap, &t1)
|
||||
AssertEqual(t, loaded, true)
|
||||
// t1 already exist but t2 not
|
||||
loaded = callbacks.LoadOrStoreVisitMap(&vistMap, []*testM{&t1, &t2, &t3})
|
||||
AssertEqual(t, loaded, false)
|
||||
loaded = callbacks.LoadOrStoreVisitMap(&vistMap, []*testM{&t2, &t3})
|
||||
AssertEqual(t, loaded, true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue