Skip to content

Instantly share code, notes, and snippets.

@kavirajk
Created July 15, 2016 11:20
Show Gist options
  • Save kavirajk/24e79d3616204238ccaa232eb64619c9 to your computer and use it in GitHub Desktop.
Save kavirajk/24e79d3616204238ccaa232eb64619c9 to your computer and use it in GitHub Desktop.
package main
import (
"testing"
"code.launchyard.com/root/myserver/utils"
"code.launchyard.com/root/myserver/models"
)
func TestResetPassword(t *testing.T) {
save_password_called := false
var user *models.User
new_password := "jedi"
// userGetter mock
userGetter = func(email string) *models.User {
user = &models.User{Password: "old_password", Email: email}
return user
}
// savePassword mock
savePassword = func(s Saver) {
save_password_called = true
}
ResetPassword("[email protected]", new_password)
expected := utils.HashString("jedi")
if user == nil {
t.Fatalf("userGetter not called")
}
if !save_password_called {
t.Errorf("savePassword not called")
}
if user.Password != expected {
t.Errorf("password not saved")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment