Created
August 19, 2016 14:32
-
-
Save therealplato/aefb4dc3b35ae44e697d1eb6e89c2075 to your computer and use it in GitHub Desktop.
assert.IsType for nil pointers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
type Foo struct{} | |
func ReturnFoo() *Foo { | |
return &Foo{} | |
} | |
func ReturnNil() *Foo { | |
return nil | |
} | |
func main() { | |
fmt.Println("Hello, playground") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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