2020-10-05 09:56:03 +00:00
|
|
|
# go (golang) cheatsheet
|
|
|
|
|
|
|
|
## testing
|
|
|
|
|
2020-10-05 09:57:11 +00:00
|
|
|
### use testify
|
|
|
|
|
|
|
|
```
|
|
|
|
import "github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
|
|
|
|
func TestSomething(t *testing.T) {
|
|
|
|
a := assert.New(t)
|
|
|
|
|
|
|
|
thing, err := functionCall()
|
|
|
|
|
|
|
|
t.Logf("%#v", thing)
|
|
|
|
|
|
|
|
a.NotNil(err)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### use %#v
|
|
|
|
|
2020-10-05 09:56:03 +00:00
|
|
|
``` go
|
|
|
|
t.Logf("%#v", eim)
|
|
|
|
```
|
|
|
|
|
|
|
|
Outputs types with keys, viz:
|
|
|
|
|
|
|
|
```
|
|
|
|
inner_test.go:17: &message.InnerMessage{
|
|
|
|
ours:(*message.InnerJSONStruct)(nil),
|
|
|
|
dstPubKey:(*cbk.CryptoBoxKey)(nil),
|
|
|
|
srcPrivKey:(*cbk.CryptoBoxKey)(nil)}
|
|
|
|
```
|