Skip to content

Commit 2ba7d73

Browse files
committed
some simple lint fixes for naming in tests, add a test that shows jmoiron#197 failing and a comment about why it fails
1 parent 54aec3f commit 2ba7d73

File tree

2 files changed

+59
-12
lines changed

2 files changed

+59
-12
lines changed

reflectx/reflect_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func TestInlineStruct(t *testing.T) {
220220

221221
type Employee struct {
222222
Name string
223-
Id int
223+
ID int
224224
}
225225
type Boss Employee
226226
type person struct {
@@ -229,7 +229,7 @@ func TestInlineStruct(t *testing.T) {
229229
}
230230
// employees columns: (employee.name employee.id boss.name boss.id)
231231

232-
em := person{Employee: Employee{Name: "Joe", Id: 2}, Boss: Boss{Name: "Dick", Id: 1}}
232+
em := person{Employee: Employee{Name: "Joe", ID: 2}, Boss: Boss{Name: "Dick", ID: 1}}
233233
ev := reflect.ValueOf(em)
234234

235235
fields := m.TypeMap(reflect.TypeOf(em))
@@ -242,8 +242,8 @@ func TestInlineStruct(t *testing.T) {
242242
t.Errorf("Expecting %s, got %s", em.Employee.Name, v.Interface().(string))
243243
}
244244
v = m.FieldByName(ev, "boss.id")
245-
if ival(v) != em.Boss.Id {
246-
t.Errorf("Expecting %s, got %s", em.Boss.Id, ival(v))
245+
if ival(v) != em.Boss.ID {
246+
t.Errorf("Expecting %s, got %s", em.Boss.ID, ival(v))
247247
}
248248
}
249249

sqlx_test.go

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,9 @@ func TestEmbeddedStructs(t *testing.T) {
470470
func TestJoinQuery(t *testing.T) {
471471
type Employee struct {
472472
Name string
473-
Id int64
474-
// BossId is an id into the employee table
475-
BossId sql.NullInt64 `db:"boss_id"`
473+
ID int64
474+
// BossID is an id into the employee table
475+
BossID sql.NullInt64 `db:"boss_id"`
476476
}
477477
type Boss Employee
478478

@@ -496,7 +496,7 @@ func TestJoinQuery(t *testing.T) {
496496
if len(em.Employee.Name) == 0 {
497497
t.Errorf("Expected non zero lengthed name.")
498498
}
499-
if em.Employee.BossId.Int64 != em.Boss.Id {
499+
if em.Employee.BossID.Int64 != em.Boss.ID {
500500
t.Errorf("Expected boss ids to match")
501501
}
502502
}
@@ -506,9 +506,9 @@ func TestJoinQuery(t *testing.T) {
506506
func TestJoinQueryNamedPointerStructs(t *testing.T) {
507507
type Employee struct {
508508
Name string
509-
Id int64
510-
// BossId is an id into the employee table
511-
BossId sql.NullInt64 `db:"boss_id"`
509+
ID int64
510+
// BossID is an id into the employee table
511+
BossID sql.NullInt64 `db:"boss_id"`
512512
}
513513
type Boss Employee
514514

@@ -536,7 +536,7 @@ func TestJoinQueryNamedPointerStructs(t *testing.T) {
536536
if len(em.Emp1.Name) == 0 || len(em.Emp2.Name) == 0 {
537537
t.Errorf("Expected non zero lengthed name.")
538538
}
539-
if em.Emp1.BossId.Int64 != em.Boss.Id || em.Emp2.BossId.Int64 != em.Boss.Id {
539+
if em.Emp1.BossID.Int64 != em.Boss.ID || em.Emp2.BossID.Int64 != em.Boss.ID {
540540
t.Errorf("Expected boss ids to match")
541541
}
542542
}
@@ -1341,6 +1341,53 @@ func TestEmbeddedMaps(t *testing.T) {
13411341
})
13421342
}
13431343

1344+
func TestIssue197(t *testing.T) {
1345+
// this test actually tests for a bug in database/sql:
1346+
// https://github.com/golang/go/issues/13905
1347+
// this potentially makes _any_ named type that is an alias for []byte
1348+
// unsafe to use in a lot of different ways (basically, unsafe to hold
1349+
// onto after loading from the database).
1350+
t.Skip()
1351+
1352+
type mybyte []byte
1353+
type Var struct{ Raw json.RawMessage }
1354+
type Var2 struct{ Raw []byte }
1355+
type Var3 struct{ Raw mybyte }
1356+
RunWithSchema(defaultSchema, t, func(db *DB, t *testing.T) {
1357+
var err error
1358+
var v, q Var
1359+
if err = db.Get(&v, `SELECT '{"a": "b"}' AS raw`); err != nil {
1360+
t.Fatal(err)
1361+
}
1362+
fmt.Printf("%s: v %s\n", db.DriverName(), v.Raw)
1363+
if err = db.Get(&q, `SELECT 'null' AS raw`); err != nil {
1364+
t.Fatal(err)
1365+
}
1366+
fmt.Printf("%s: v %s\n", db.DriverName(), v.Raw)
1367+
1368+
var v2, q2 Var2
1369+
if err = db.Get(&v2, `SELECT '{"a": "b"}' AS raw`); err != nil {
1370+
t.Fatal(err)
1371+
}
1372+
fmt.Printf("%s: v2 %s\n", db.DriverName(), v2.Raw)
1373+
if err = db.Get(&q2, `SELECT 'null' AS raw`); err != nil {
1374+
t.Fatal(err)
1375+
}
1376+
fmt.Printf("%s: v2 %s\n", db.DriverName(), v2.Raw)
1377+
1378+
var v3, q3 Var3
1379+
if err = db.QueryRow(`SELECT '{"a": "b"}' AS raw`).Scan(&v3.Raw); err != nil {
1380+
t.Fatal(err)
1381+
}
1382+
fmt.Printf("v3 %s\n", v3.Raw)
1383+
if err = db.QueryRow(`SELECT '{"c": "d"}' AS raw`).Scan(&q3.Raw); err != nil {
1384+
t.Fatal(err)
1385+
}
1386+
fmt.Printf("v3 %s\n", v3.Raw)
1387+
t.Fail()
1388+
})
1389+
}
1390+
13441391
func TestIn(t *testing.T) {
13451392
// some quite normal situations
13461393
type tr struct {

0 commit comments

Comments
 (0)