Move everything to better package structure
This commit is contained in:
parent
f6b4d3c6fd
commit
5149df8359
40 changed files with 241 additions and 86 deletions
queries
67
queries/helpers_test.go
Normal file
67
queries/helpers_test.go
Normal file
|
@ -0,0 +1,67 @@
|
|||
package queries
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gopkg.in/nullbio/null.v5"
|
||||
)
|
||||
|
||||
type testObj struct {
|
||||
ID int
|
||||
Name string `db:"TestHello"`
|
||||
HeadSize int
|
||||
}
|
||||
|
||||
func TestNonZeroDefaultSet(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
type Anything struct {
|
||||
ID int
|
||||
Name string
|
||||
CreatedAt *time.Time
|
||||
UpdatedAt null.Time
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
tests := []struct {
|
||||
Defaults []string
|
||||
Obj interface{}
|
||||
Ret []string
|
||||
}{
|
||||
{
|
||||
[]string{"id"},
|
||||
Anything{Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}},
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
[]string{"id"},
|
||||
Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}},
|
||||
[]string{"id"},
|
||||
},
|
||||
{
|
||||
[]string{},
|
||||
Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}},
|
||||
[]string{},
|
||||
},
|
||||
{
|
||||
[]string{"id", "created_at", "updated_at"},
|
||||
Anything{ID: 5, Name: "hi", CreatedAt: nil, UpdatedAt: null.Time{Valid: false}},
|
||||
[]string{"id"},
|
||||
},
|
||||
{
|
||||
[]string{"id", "created_at", "updated_at"},
|
||||
Anything{ID: 5, Name: "hi", CreatedAt: &now, UpdatedAt: null.Time{Valid: true, Time: time.Now()}},
|
||||
[]string{"id", "created_at", "updated_at"},
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
z := NonZeroDefaultSet(test.Defaults, test.Obj)
|
||||
if !reflect.DeepEqual(test.Ret, z) {
|
||||
t.Errorf("[%d] mismatch:\nWant: %#v\nGot: %#v", i, test.Ret, z)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue