diff options
| author | Horus3 | 2015-03-19 16:24:10 +0100 |
|---|---|---|
| committer | Horus3 | 2015-03-19 16:24:10 +0100 |
| commit | e14cf986a916e1a7361b058224ef3badd3aad776 (patch) | |
| tree | a5ae9b523cd9999bcb51daccb7864298606cac63 /email_test.go | |
| parent | f334c93c0364d14a2b55641b155ad58f715a4b39 (diff) | |
| download | freemail-e14cf986a916e1a7361b058224ef3badd3aad776.tar.gz | |
OOP. Creates virtual_domains and virtual_users now. Enhanced test suite.
Diffstat (limited to 'email_test.go')
| -rw-r--r-- | email_test.go | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/email_test.go b/email_test.go index 887eb8d..431d6e3 100644 --- a/email_test.go +++ b/email_test.go @@ -6,32 +6,54 @@ import ( ) func TestCreateEmail(t *testing.T) { - InitDB() + vU := VirtualUser{Email: "test@example.com", Password: "password"} t.Log("Using database: " + os.Getenv("FREEMAIL_DB_CREDENTIALS")) - if success, err := CreateEmail("test@example.com", "password"); err != nil || !success { - t.Fatal("Can't create email.", err) + if !vU.CreateEmail() { + t.Fatal("Can't create email.") } else { t.Log("test@example.com") } } + func TestEmailExists(t *testing.T) { t.Log("Using database: " + os.Getenv("FREEMAIL_DB_CREDENTIALS")) - vU := VirtualUser{} - vU.Email = "test@example.com" - /* - vU := VirtualUser{} - vU.Email = "test@example.com" - //if err := Db.Save(&vU); err != nil { - if !Db.NewRecord(&vU) { - //t.Fatal("Saving record to database failed.", err) - t.Fatal("Saving record to database failed.") - } - */ - if !EmailExists(vU.Email) { - t.Log(EmailExists(vU.Email)) + vU := VirtualUser{Email: "test@example.com"} + if !vU.EmailExists() { t.Fatal("Email should exist. Expected bool true.") } - if EmailExists("foo@example.com") { + vU.Email = "foo@example.com" + if vU.EmailExists() { t.Fatal("Email doesn't exist. Expected bool false.") } } + +func TestValidateEmail(t *testing.T) { + if ValidateEmail("foo") { + t.Fatal("'foo' is no valid email.") + } + if ValidateEmail("foo@") { + t.Fatal("'foo@' is no valid email.") + } + if ValidateEmail("@foo") { + t.Fatal("'foo' is no valid email.") + } + if ValidateEmail("foo@bar@foo") { + t.Fatal("'foo@bar@foo' is not a valid email.") + } + if !ValidateEmail("foo@bar") { + t.Fatal("'foo@bar' is a valid email.") + } +} + +func TestValidateAlias(t *testing.T) { + if ValidateAlias("foo") { + t.Fatal("'foo' is not a valid alias.") + } +} + +func TestGetDomain(t *testing.T) { + domain := GetDomain("foo@example.org") + if domain != "example.org" { + t.Fatal("Can't get the domain from the adress.") + } +} |
