2016-01-26 13:14:10 +02:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
2016-01-26 13:42:44 +02:00
|
|
|
"os"
|
2016-01-26 13:14:10 +02:00
|
|
|
"testing"
|
2016-01-26 16:09:33 +02:00
|
|
|
"time"
|
2016-01-26 13:14:10 +02:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2016-01-26 13:42:44 +02:00
|
|
|
var (
|
2016-01-26 16:09:33 +02:00
|
|
|
dnsimpleLiveTest bool
|
2016-01-26 17:37:50 +02:00
|
|
|
dnsimpleEmail string
|
|
|
|
dnsimpleAPIKey string
|
|
|
|
dnsimpleDomain string
|
2016-01-26 13:42:44 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
dnsimpleEmail = os.Getenv("DNSIMPLE_EMAIL")
|
|
|
|
dnsimpleAPIKey = os.Getenv("DNSIMPLE_API_KEY")
|
2016-01-26 16:09:33 +02:00
|
|
|
dnsimpleDomain = os.Getenv("DNSIMPLE_DOMAIN")
|
|
|
|
if len(dnsimpleEmail) > 0 && len(dnsimpleAPIKey) > 0 && len(dnsimpleDomain) > 0 {
|
|
|
|
dnsimpleLiveTest = true
|
|
|
|
}
|
2016-01-26 13:42:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func restoreDNSimpleEnv() {
|
|
|
|
os.Setenv("DNSIMPLE_EMAIL", dnsimpleEmail)
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", dnsimpleAPIKey)
|
|
|
|
}
|
|
|
|
|
2016-01-26 13:14:10 +02:00
|
|
|
func TestNewDNSProviderDNSimpleValid(t *testing.T) {
|
2016-01-26 13:42:44 +02:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-01-26 13:14:10 +02:00
|
|
|
_, err := NewDNSProviderDNSimple("example@example.com", "123")
|
|
|
|
assert.NoError(t, err)
|
2016-01-26 13:42:44 +02:00
|
|
|
restoreDNSimpleEnv()
|
|
|
|
}
|
|
|
|
func TestNewDNSProviderDNSimpleValidEnv(t *testing.T) {
|
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "example@example.com")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "123")
|
|
|
|
_, err := NewDNSProviderDNSimple("", "")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
restoreDNSimpleEnv()
|
2016-01-26 13:14:10 +02:00
|
|
|
}
|
2016-01-26 13:25:51 +02:00
|
|
|
|
|
|
|
func TestNewDNSProviderDNSimpleMissingCredErr(t *testing.T) {
|
2016-01-26 13:42:44 +02:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-01-26 13:25:51 +02:00
|
|
|
_, err := NewDNSProviderDNSimple("", "")
|
|
|
|
assert.EqualError(t, err, "DNSimple credentials missing")
|
2016-01-26 13:42:44 +02:00
|
|
|
restoreDNSimpleEnv()
|
2016-01-26 13:25:51 +02:00
|
|
|
}
|
2016-01-26 16:09:33 +02:00
|
|
|
|
|
|
|
func TestLiveDNSimplePresent(t *testing.T) {
|
|
|
|
if !dnsimpleLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleAPIKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(dnsimpleDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveDNSimpleCleanUp(t *testing.T) {
|
|
|
|
if !dnsimpleLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
|
2016-02-21 05:14:32 +02:00
|
|
|
provider, err := NewDNSProviderDNSimple(dnsimpleEmail, dnsimpleAPIKey)
|
2016-01-26 16:09:33 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(dnsimpleDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|