Skip to content

Instantly share code, notes, and snippets.

@therealplato
Created August 19, 2016 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save therealplato/aefb4dc3b35ae44e697d1eb6e89c2075 to your computer and use it in GitHub Desktop.
Save therealplato/aefb4dc3b35ae44e697d1eb6e89c2075 to your computer and use it in GitHub Desktop.
assert.IsType for nil pointers
package main
import (
"fmt"
)
type Foo struct{}
func ReturnFoo() *Foo {
return &Foo{}
}
func ReturnNil() *Foo {
return nil
}
func main() {
fmt.Println("Hello, playground")
}
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFoo(t *testing.T) {
x := ReturnNil()
assert.IsType(t, &Foo{}, x)
y := ReturnFoo()
assert.IsType(t, &Foo{}, y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment