summaryrefslogtreecommitdiff
path: root/email_test.go
blob: 1f102ee5fc1e490169ce0a0870bf4103f2e6b7dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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.")
	}
}