I have these structs:
type Event interface { Accept(EventVisitor) } type Like struct { } func (l *Like) Accept(visitor EventVisitor) { visitor.visitLike(l) }
How can I test that event
is a Like
instance?
func TestEventCreation(t *testing.T) { event, err := New(0) if err != nil { t.Error(err) } if reflect.TypeOf(event) != Like { t.Error("Assertion error") } }
I get:
Type Like is not an expression event Event
You could just do a type assertion and see if it fails:
event, err := New(0) if err != nil { t.Error(err) } _, ok := event.(Like) if !ok { t.Error("Assertion error") }
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