go-mocket
go-mocket copied to clipboard
What is this testing? I can't get this library to actual fail a test.
func SetupTests(t *testing.T) *gorm.DB {
mocket.Catcher.Register()
mocket.Catcher.Logging = true
db, err := gorm.Open(mocket.DriverName, "connection_string")
if err != nil {
t.Fatalf(err.Error())
}
return db
}
func TestInsertStoragePool(t *testing.T) {
cases := []struct {
givenPool StoragePool
wantedError error
}{
{ // happy path
givenPool: StoragePool{
Name: "POOL1",
PoolId: "1",
Type: "NetworkFilesystem",
Volumes: []Volume{
{
Name: "VOL01",
StorageId: "1",
Type: "ROOT",
VolumeId: "1",
},
},
},
wantedError: nil,
},
}
for _, c := range cases {
db := SetupTests(t)
db.LogMode(true)
reply := []map[string]interface{}{{"id": 5}}
mocket.Catcher.Reset().NewMock().WithQuery("INSERT INTO \"storage_pools\"").WithID(int64(5)).WithArgs(c.givenPool).WithReply(reply)
err := InsertStoragePool(db, &c.givenPool)
if err != nil {
t.Error(err)
}
fmt.Fprintf(os.Stderr, "\nPOOLID=%d\n", c.givenPool.ID)
}
}
What is this testing?
- The primary key is getting set to 5577006791947779410, not 5.
- The WithReply is apparently not doing anything because this is not failing.
- My Type column above is an enumerated type. When I set the Type to an invalid value, this test still succeeds in flying colors.
According to go test, this test succeeds with flying colors.
I found something similar, for testing set the expected query to just UPDATE
while the underlying query is an INSERT
statement. the test still passes.