Skip to content

Instantly share code, notes, and snippets.

@luizbranco luizbranco/test.go
Last active Feb 20, 2018

Embed
What would you like to do?
Testing with intefaces
func TestUserActivation(t *testing T) {
email := Email{}
mailer := &TestingMailer{}
t.Run("user activation email sent successfully", func(t *testing.T) {
err := UserActivation(email)
if err != nil {
t.Errorf("UserActivation(%v) expected no error, got %s", email, err)
}
if len(mailer.Emails) != 1 || reflect.DeepEqual(mailer.Emails[0], email) {
t.Errorf("UserActivation(%v) expected to have queued email", email)
}
}
t.Run("user activation email failed", func(t *testing.T) {
mailer.Error = errors.New("connection problem")
err = UserActivation(email)
if err == nil {
t.Errorf("UserActivation(%v) expected error, got none")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.