2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-07-13 18:51:40 +02:00
|
|
|
var {{$varNameSingular}}DBTypes = map[string]string{{"{"}}{{.Table.Columns | columnDBTypes | makeStringMap}}{{"}"}}
|
|
|
|
|
2016-08-11 14:26:49 +02:00
|
|
|
func {{$varNameSingular}}CompareVals(o *{{$tableNameSingular}}, j *{{$tableNameSingular}}, equal bool, blacklist ...string) error {
|
2016-07-16 14:11:10 +02:00
|
|
|
{{- range $key, $value := .Table.Columns -}}
|
2016-07-13 18:51:40 +02:00
|
|
|
{{if eq $value.Type "null.Time"}}
|
2016-08-11 14:26:49 +02:00
|
|
|
if ((equal && o.{{titleCase $value.Name}}.Time.Format("02/01/2006") != j.{{titleCase $value.Name}}.Time.Format("02/01/2006")) ||
|
|
|
|
(!equal && o.{{titleCase $value.Name}}.Time.Format("02/01/2006") == j.{{titleCase $value.Name}}.Time.Format("02/01/2006"))) &&
|
2016-08-14 01:03:34 +02:00
|
|
|
!strmangle.SetInclude("{{$value.Name}}", blacklist) {
|
2016-08-11 14:26:49 +02:00
|
|
|
return errors.New(fmt.Sprintf("NullTime {{$value.Name}} unexpected value, got:\nStruct: %#v\nResponse: %#v\n\n", o.{{titleCase $value.Name}}.Time.Format("02/01/2006"), j.{{titleCase $value.Name}}.Time.Format("02/01/2006")))
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
{{else if eq $value.Type "time.Time"}}
|
2016-08-11 14:26:49 +02:00
|
|
|
if ((equal && o.{{titleCase $value.Name}}.Format("02/01/2006") != j.{{titleCase $value.Name}}.Format("02/01/2006")) ||
|
|
|
|
(!equal && o.{{titleCase $value.Name}}.Format("02/01/2006") == j.{{titleCase $value.Name}}.Format("02/01/2006"))) &&
|
2016-08-14 01:03:34 +02:00
|
|
|
!strmangle.SetInclude("{{$value.Name}}", blacklist) {
|
2016-08-11 14:26:49 +02:00
|
|
|
return errors.New(fmt.Sprintf("Time {{$value.Name}} unexpected value, got:\nStruct: %#v\nResponse: %#v\n\n", o.{{titleCase $value.Name}}.Format("02/01/2006"), j.{{titleCase $value.Name}}.Format("02/01/2006")))
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
{{else if eq $value.Type "[]byte"}}
|
2016-08-11 14:26:49 +02:00
|
|
|
if ((equal && !byteSliceEqual(o.{{titleCase $value.Name}}, j.{{titleCase $value.Name}})) ||
|
|
|
|
(!equal && byteSliceEqual(o.{{titleCase $value.Name}}, j.{{titleCase $value.Name}}))) &&
|
2016-08-14 01:03:34 +02:00
|
|
|
!strmangle.SetInclude("{{$value.Name}}", blacklist) {
|
2016-08-11 14:26:49 +02:00
|
|
|
return errors.New(fmt.Sprintf("Expected {{$value.Name}} columns to match, got:\nStruct: %#v\nResponse: %#v\n\n", o.{{titleCase $value.Name}}, j.{{titleCase $value.Name}}))
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
{{else}}
|
2016-08-11 14:26:49 +02:00
|
|
|
if ((equal && j.{{titleCase $value.Name}} != o.{{titleCase $value.Name}}) ||
|
|
|
|
(!equal && j.{{titleCase $value.Name}} == o.{{titleCase $value.Name}})) &&
|
2016-08-14 01:03:34 +02:00
|
|
|
!strmangle.SetInclude("{{$value.Name}}", blacklist) {
|
2016-08-11 14:26:49 +02:00
|
|
|
return errors.New(fmt.Sprintf("Expected {{$value.Name}} columns to match, got:\nStruct: %#v\nResponse: %#v\n\n", o.{{titleCase $value.Name}}, j.{{titleCase $value.Name}}))
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
{{end}}
|
2016-07-16 14:11:10 +02:00
|
|
|
{{- end -}}
|
2016-08-11 14:26:49 +02:00
|
|
|
|
|
|
|
return nil
|
2016-07-13 18:51:40 +02:00
|
|
|
}
|
|
|
|
|
2016-06-10 06:40:02 +02:00
|
|
|
func Test{{$tableNamePlural}}InPrimaryKeyArgs(t *testing.T) {
|
|
|
|
var err error
|
|
|
|
var o {{$tableNameSingular}}
|
|
|
|
o = {{$tableNameSingular}}{}
|
|
|
|
|
2016-07-14 07:09:05 +02:00
|
|
|
if err = boil.RandomizeStruct(&o, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-06-10 06:40:02 +02:00
|
|
|
t.Errorf("Could not randomize struct: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
args := o.inPrimaryKeyArgs()
|
|
|
|
|
|
|
|
if len(args) != len({{$varNameSingular}}PrimaryKeyColumns) {
|
|
|
|
t.Errorf("Expected args to be len %d, but got %d", len({{$varNameSingular}}PrimaryKeyColumns), len(args))
|
|
|
|
}
|
|
|
|
|
2016-06-12 08:41:04 +02:00
|
|
|
{{range $key, $value := .Table.PKey.Columns}}
|
2016-06-10 06:40:02 +02:00
|
|
|
if o.{{titleCase $value}} != args[{{$key}}] {
|
|
|
|
t.Errorf("Expected args[{{$key}}] to be value of o.{{titleCase $value}}, but got %#v", args[{{$key}}])
|
|
|
|
}
|
|
|
|
{{- end}}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test{{$tableNamePlural}}SliceInPrimaryKeyArgs(t *testing.T) {
|
|
|
|
var err error
|
2016-07-16 16:15:14 +02:00
|
|
|
o := make({{$tableNameSingular}}Slice, 3)
|
2016-06-10 06:40:02 +02:00
|
|
|
|
2016-07-14 07:09:05 +02:00
|
|
|
if err = boil.RandomizeSlice(&o, {{$varNameSingular}}DBTypes, true); err != nil {
|
2016-06-10 06:40:02 +02:00
|
|
|
t.Errorf("Could not randomize slice: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
args := o.inPrimaryKeyArgs()
|
|
|
|
|
|
|
|
if len(args) != len({{$varNameSingular}}PrimaryKeyColumns) * 3 {
|
|
|
|
t.Errorf("Expected args to be len %d, but got %d", len({{$varNameSingular}}PrimaryKeyColumns) * 3, len(args))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len({{$varNameSingular}}PrimaryKeyColumns) * 3; i++ {
|
2016-06-12 08:41:04 +02:00
|
|
|
{{range $key, $value := .Table.PKey.Columns}}
|
2016-06-10 06:40:02 +02:00
|
|
|
if o[i].{{titleCase $value}} != args[i] {
|
|
|
|
t.Errorf("Expected args[%d] to be value of o.{{titleCase $value}}, but got %#v", i, args[i])
|
|
|
|
}
|
2016-06-12 08:41:04 +02:00
|
|
|
{{- end}}
|
2016-06-10 06:40:02 +02:00
|
|
|
}
|
|
|
|
}
|