(t *testing.T)
| 19 | ) |
| 20 | |
| 21 | func TestScannerValuer(t *testing.T) { |
| 22 | DB.Migrator().DropTable(&ScannerValuerStruct{}) |
| 23 | if err := DB.Migrator().AutoMigrate(&ScannerValuerStruct{}); err != nil { |
| 24 | t.Fatalf("no error should happen when migrate scanner, valuer struct, got error %v", err) |
| 25 | } |
| 26 | |
| 27 | data := ScannerValuerStruct{ |
| 28 | Name: sql.NullString{String: "name", Valid: true}, |
| 29 | Gender: &sql.NullString{String: "M", Valid: true}, |
| 30 | Age: sql.NullInt64{Int64: 18, Valid: true}, |
| 31 | Male: sql.NullBool{Bool: true, Valid: true}, |
| 32 | Height: sql.NullFloat64{Float64: 1.8888, Valid: true}, |
| 33 | Birthday: sql.NullTime{Time: time.Now(), Valid: true}, |
| 34 | Allergen: NullString{sql.NullString{String: "Allergen", Valid: true}}, |
| 35 | Password: EncryptedData("pass1"), |
| 36 | Bytes: []byte("byte"), |
| 37 | Num: 18, |
| 38 | Strings: StringsSlice{"a", "b", "c"}, |
| 39 | Structs: StructsSlice{ |
| 40 | {"name1", "value1"}, |
| 41 | {"name2", "value2"}, |
| 42 | }, |
| 43 | Role: Role{Name: "admin"}, |
| 44 | ExampleStruct: ExampleStruct{"name", "value1"}, |
| 45 | ExampleStructPtr: &ExampleStruct{"name", "value2"}, |
| 46 | } |
| 47 | |
| 48 | if err := DB.Create(&data).Error; err != nil { |
| 49 | t.Fatalf("No error should happened when create scanner valuer struct, but got %v", err) |
| 50 | } |
| 51 | |
| 52 | var result ScannerValuerStruct |
| 53 | |
| 54 | if err := DB.Find(&result, "id = ?", data.ID).Error; err != nil { |
| 55 | t.Fatalf("no error should happen when query scanner, valuer struct, but got %v", err) |
| 56 | } |
| 57 | |
| 58 | if result.ExampleStructPtr.Val != "value2" { |
| 59 | t.Errorf(`ExampleStructPtr.Val should equal to "value2", but got %v`, result.ExampleStructPtr.Val) |
| 60 | } |
| 61 | |
| 62 | if result.ExampleStruct.Val != "value1" { |
| 63 | t.Errorf(`ExampleStruct.Val should equal to "value1", but got %#v`, result.ExampleStruct) |
| 64 | } |
| 65 | AssertObjEqual(t, data, result, "Name", "Gender", "Age", "Male", "Height", "Birthday", "Password", "Bytes", "Num", "Strings", "Structs") |
| 66 | } |
| 67 | |
| 68 | func TestScannerValuerWithFirstOrCreate(t *testing.T) { |
| 69 | DB.Migrator().DropTable(&ScannerValuerStruct{}) |
nothing calls this directly
no test coverage detected