summaryrefslogtreecommitdiff
path: root/email_test.go
blob: 431d6e3b026c9440f6f155de8dd963cb4ddc7ba1 (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
53
54
55
56
57
58
59
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.")
	}
}

func TestGetDomain(t *testing.T) {
	domain := GetDomain("foo@example.org")
	if domain != "example.org" {
		t.Fatal("Can't get the domain from the adress.")
	}
}