{ "@context":[ "https://www.w3.org/ns/activitystreams", {"Hashtag":"as:Hashtag"} ], "published":"2024-02-17T14:59:18.514Z", "attributedTo":"https://k.matthias.org/actors/relistan", "to":["https://www.w3.org/ns/activitystreams#Public"], "cc":["https://k.matthias.org/actors/relistan/followers"], "content":"

Go `sqlmock` from Data Dog can be useful for making sure you know exactly which queries are being sent to the DB. But it has a limited set of type matchers and when matchers don't match, it's so hard to figure out what was actually sent. It supports custom matchers.

I figured out a little pattern I like there I pass `t` from the test (`testing.T`) into the custom matcher's struct and then use `t.Log()` to pass back what the heck was wrong with the value passed. So many WTFs saved when tests fail. #Golang

type MicrosTimestamp struct {\r\n    t *testing.T\r\n}\r\nfunc (r MicrosTimestamp) Match(v driver.Value) bool {\r\n i, ok := v.(int64)\r\n    if !ok {\r\n        r.t.Log(fmt.Sprintf(\"TESTS: MicrosTimestamp got %v which is not an int64\", v))\r\n        return false\r\n    }\r\n...
", "mediaType":"text/html", "attachment":[], "tag":[ {"type":"Hashtag","name":"#Golang","href":"https://k.matthias.org/tags/Golang"} ], "type":"Note", "id":"https://k.matthias.org/objects/IHxgk8yQ2fk" }