package main import ( "os" "testing" ) func TestCreateEmail(t *testing.T) { vU := VirtualUser{Email: "test@example.com", Password: "password"} t.Log("Using database: " + os.Getenv("FREEMAIL_DB_CREDENTIALS")) 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{Email: "test@example.com"} if !vU.EmailExists() { t.Fatal("Email should exist. Expected bool true.") } 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.") } }