I'm writing a test for reading/writing a struct in a DB and one of its fields is a timestamp which is auto-calculated in the DB. So when I write the struct its timestamp is 0 but when I read it from the DB the timestamp has an actual value.
I want to compare the two values but to ignore the auto-calculated field. Is it possible?
Set the other "except" field prior to testing:
now := time.Now()
expected := SomeStruct{
ID: 123,
Name: "Test",
Timestamp: now,
...
}
result, _ := db.Select(....)
result.Timeestamp = now
if !reflect.DeepEqual(result, expected) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With