github.com/systematiccaos/gorm@v1.22.6/clause/clause_test.go (about) 1 package clause_test 2 3 import ( 4 "reflect" 5 "strings" 6 "sync" 7 "testing" 8 9 "github.com/systematiccaos/gorm" 10 "github.com/systematiccaos/gorm/clause" 11 "github.com/systematiccaos/gorm/schema" 12 "github.com/systematiccaos/gorm/utils/tests" 13 ) 14 15 var db, _ = gorm.Open(tests.DummyDialector{}, nil) 16 17 func checkBuildClauses(t *testing.T, clauses []clause.Interface, result string, vars []interface{}) { 18 var ( 19 buildNames []string 20 buildNamesMap = map[string]bool{} 21 user, _ = schema.Parse(&tests.User{}, &sync.Map{}, db.NamingStrategy) 22 stmt = gorm.Statement{DB: db, Table: user.Table, Schema: user, Clauses: map[string]clause.Clause{}} 23 ) 24 25 for _, c := range clauses { 26 if _, ok := buildNamesMap[c.Name()]; !ok { 27 buildNames = append(buildNames, c.Name()) 28 buildNamesMap[c.Name()] = true 29 } 30 31 stmt.AddClause(c) 32 } 33 34 stmt.Build(buildNames...) 35 36 if strings.TrimSpace(stmt.SQL.String()) != result { 37 t.Errorf("SQL expects %v got %v", result, stmt.SQL.String()) 38 } 39 40 if !reflect.DeepEqual(stmt.Vars, vars) { 41 t.Errorf("Vars expects %+v got %v", stmt.Vars, vars) 42 } 43 }