
use golangci/golangci-lint-action instead of reviewdog/action-golangci-lint as the second was not reporting any failures even if there was some. Report code coverage with codecov/codecov-action I have set some flags per dialect and go version Several linters has been fixed, some disabled so the build can pass
43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package clause_test
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
func TestGroupBy(t *testing.T) {
|
|
results := []struct {
|
|
Clauses []clause.Interface
|
|
Result string
|
|
Vars []interface{}
|
|
}{
|
|
{
|
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.GroupBy{
|
|
Columns: []clause.Column{{Name: "role"}},
|
|
Having: []clause.Expression{clause.Eq{"role", "admin"}},
|
|
}},
|
|
"SELECT * FROM `users` GROUP BY `role` HAVING `role` = ?",
|
|
[]interface{}{"admin"},
|
|
},
|
|
{
|
|
[]clause.Interface{clause.Select{}, clause.From{}, clause.GroupBy{
|
|
Columns: []clause.Column{{Name: "role"}},
|
|
Having: []clause.Expression{clause.Eq{"role", "admin"}},
|
|
}, clause.GroupBy{
|
|
Columns: []clause.Column{{Name: "gender"}},
|
|
Having: []clause.Expression{clause.Neq{"gender", "U"}},
|
|
}},
|
|
"SELECT * FROM `users` GROUP BY `role`,`gender` HAVING `role` = ? AND `gender` <> ?",
|
|
[]interface{}{"admin", "U"},
|
|
},
|
|
}
|
|
|
|
for idx, result := range results {
|
|
t.Run(fmt.Sprintf("case #%v", idx), func(t *testing.T) {
|
|
checkBuildClauses(t, result.Clauses, result.Result, result.Vars)
|
|
})
|
|
}
|
|
}
|