CHORE move the test cases located in the files convert_map_test.go and visit_map_test.go into the file helper_test.go.
This commit is contained in:
parent
6f83955657
commit
6d975db6e8
@ -8,6 +8,36 @@ import (
|
|||||||
"gorm.io/gorm/clause"
|
"gorm.io/gorm/clause"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestLoadOrStoreVisitMap(t *testing.T) {
|
||||||
|
var vm visitMap
|
||||||
|
var loaded bool
|
||||||
|
type testM struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
t1 := testM{Name: "t1"}
|
||||||
|
t2 := testM{Name: "t2"}
|
||||||
|
t3 := testM{Name: "t3"}
|
||||||
|
|
||||||
|
vm = make(visitMap)
|
||||||
|
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf(&t1)); loaded {
|
||||||
|
t.Fatalf("loaded should be false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf(&t1)); !loaded {
|
||||||
|
t.Fatalf("loaded should be true")
|
||||||
|
}
|
||||||
|
|
||||||
|
// t1 already exist but t2 not
|
||||||
|
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf([]*testM{&t1, &t2, &t3})); loaded {
|
||||||
|
t.Fatalf("loaded should be false")
|
||||||
|
}
|
||||||
|
|
||||||
|
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf([]*testM{&t2, &t3})); !loaded {
|
||||||
|
t.Fatalf("loaded should be true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestConvertMapToValuesForCreate(t *testing.T) {
|
func TestConvertMapToValuesForCreate(t *testing.T) {
|
||||||
testCase := []struct {
|
testCase := []struct {
|
||||||
name string
|
name string
|
@ -1,36 +0,0 @@
|
|||||||
package callbacks
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestLoadOrStoreVisitMap(t *testing.T) {
|
|
||||||
var vm visitMap
|
|
||||||
var loaded bool
|
|
||||||
type testM struct {
|
|
||||||
Name string
|
|
||||||
}
|
|
||||||
|
|
||||||
t1 := testM{Name: "t1"}
|
|
||||||
t2 := testM{Name: "t2"}
|
|
||||||
t3 := testM{Name: "t3"}
|
|
||||||
|
|
||||||
vm = make(visitMap)
|
|
||||||
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf(&t1)); loaded {
|
|
||||||
t.Fatalf("loaded should be false")
|
|
||||||
}
|
|
||||||
|
|
||||||
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf(&t1)); !loaded {
|
|
||||||
t.Fatalf("loaded should be true")
|
|
||||||
}
|
|
||||||
|
|
||||||
// t1 already exist but t2 not
|
|
||||||
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf([]*testM{&t1, &t2, &t3})); loaded {
|
|
||||||
t.Fatalf("loaded should be false")
|
|
||||||
}
|
|
||||||
|
|
||||||
if loaded = loadOrStoreVisitMap(&vm, reflect.ValueOf([]*testM{&t2, &t3})); !loaded {
|
|
||||||
t.Fatalf("loaded should be true")
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user