blob: 456d3013ee3602db5f1afe91787c1d964e70066b (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package main
import (
"flag"
"os"
"testing"
)
var testExternal = flag.Bool("external", false, "allow use of external networks during long test")
func TestCreateDomain(t *testing.T) {
d := VirtualDomain{Name: "example.org"}
if !d.CreateDomain() {
t.Fatal("Creating domain failed.")
}
}
func TestDomainExists(t *testing.T) {
d := VirtualDomain{Name: "blablabla"}
if d.DomainExists() {
t.Fatal("'" + d.Name + "' does not exists.")
}
d.Name = "example.org"
if !d.DomainExists() {
t.Fatal("'" + d.Name + "' should exist.")
}
}
func TestValidateDomain(t *testing.T) {
d := VirtualDomain{Name: "blablabla"}
if d.ValidateDomain() {
t.Fatal(d.Name + " is not a valid domain.")
}
d.Name = "dfalsdf.adfjalf.example.org"
if d.ValidateDomain() {
t.Fatal("'" + d.Name + "' is not a valid domain.")
}
d.Name = "https://google.com"
if d.ValidateDomain() {
t.Fatal("'" + d.Name + "' is not a valid domain.")
}
d.Name = "google.com"
if !d.ValidateDomain() {
t.Fatal("'" + d.Name + "' is a valid domain.")
}
}
func TestValidateDomainMX(t *testing.T) {
if testing.Short() || !*testExternal {
t.Skip("Skipping test to avoid external network.")
}
d := VirtualDomain{Name: "heise.de"}
if d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
t.Fatal("heise.de MX record doesn't point to this server.")
}
d.Name = "iamfabulous.de"
if !d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) {
t.Fatal(os.Getenv("FREEMAIL_SMTP_MAILER_MX") + " MX should point to this server.")
}
}
func TestGetDomain(t *testing.T) {
domain := GetDomain("foo@example.org")
if domain != "example.org" {
t.Fatal("Can't get the domain from the adress.")
}
}
func TestGetPrimaryKey(t *testing.T) {
d := VirtualDomain{Name: "example.org"}
if d.GetPrimaryKey() != 1 {
t.Fatal("Primary key should be 1.")
}
}
|