I'm trying to get some old code to pass its unit tests. The test that's giving me problems is here:
func Test1(t *testing.T){
//Code
testDevice := Device{
ID: 1,
Guid: "C6",
Name: "test device",
}
err := Dbmap.Insert(&testDevice)
So(err, ShouldBeNil)
//More code
}
When I run go test
, this returns:
'sql: Scan error on column index 0: converting driver.Value type <nil> ("<nil>") to a int64: invalid syntax'
This is strange because I'm passing it 1, an integer. The device struct is defined here:
type Device struct {
ID int64 `db:"id"`
Guid string
Name string
}
Here's the schema for the Postgres table it's inserting into:
CREATE TABLE devices(
ID INTEGER,
Guid VARCHAR,
Name VARCHAR
);
I've tried using the sql.NillInt64
type, but that doesn't seem to fix the problem. It feels like somehow, gorp, go, or postgres is interpreting the integer as a nil there. As a final data point, this is all running in various Docker containers, though I don't think this problem is related to Docker. Any insights?