package main import ( "os" "testing" ) 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) { if testing.Short() || !*testExternal { t.Skip("Skipping test to avoid external network.") } d := VirtualDomain{Name: "blablabla"} if d.ValidateDomain("blablabla") { t.Fatal(d.Name + " is not a valid domain.") } d.Name = "dfalsdf.adfjalf.example.org" if d.ValidateDomain("dfalsdf.adfjalf.example.org") { t.Fatal("'" + d.Name + "' is not a valid domain.") } d.Name = "https://google.com" if d.ValidateDomain("https://google.com") { t.Fatal("'" + d.Name + "' is not a valid domain.") } d.Name = "google.com" if d.ValidateDomain("wikipedia.de") { t.Fatal("'" + d.Name + "' and wikipedia.de do not share IPs.") } d.Name = "localhost" if !d.ValidateDomain("localhost") { 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: "google.com"} if d.ValidateDomainMX(os.Getenv("FREEMAIL_SMTP_MAILER_MX")) { t.Fatal("google.cm 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.") } }