2016-01-26 11:14:10 +00:00
|
|
|
package acme
|
|
|
|
|
|
|
|
import (
|
2016-01-26 11:42:44 +00:00
|
|
|
"os"
|
2016-01-26 11:14:10 +00:00
|
|
|
"testing"
|
2016-01-26 14:09:33 +00:00
|
|
|
"time"
|
2016-01-26 11:14:10 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2016-01-26 11:42:44 +00:00
|
|
|
var (
|
2016-01-26 14:09:33 +00:00
|
|
|
dnsimpleLiveTest bool
|
2016-01-26 15:37:50 +00:00
|
|
|
dnsimpleEmail string
|
|
|
|
dnsimpleAPIKey string
|
|
|
|
dnsimpleDomain string
|
2016-01-26 11:42:44 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
dnsimpleEmail = os.Getenv("DNSIMPLE_EMAIL")
|
|
|
|
dnsimpleAPIKey = os.Getenv("DNSIMPLE_API_KEY")
|
2016-01-26 14:09:33 +00:00
|
|
|
dnsimpleDomain = os.Getenv("DNSIMPLE_DOMAIN")
|
|
|
|
if len(dnsimpleEmail) > 0 && len(dnsimpleAPIKey) > 0 && len(dnsimpleDomain) > 0 {
|
|
|
|
dnsimpleLiveTest = true
|
|
|
|
}
|
2016-01-26 11:42:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func restoreDNSimpleEnv() {
|
|
|
|
os.Setenv("DNSIMPLE_EMAIL", dnsimpleEmail)
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", dnsimpleAPIKey)
|
|
|
|
}
|
|
|
|
|
2016-01-26 11:14:10 +00:00
|
|
|
func TestNewDNSProviderDNSimpleValid(t *testing.T) {
|
2016-01-26 11:42:44 +00:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-01-26 11:14:10 +00:00
|
|
|
_, err := NewDNSProviderDNSimple("example@example.com", "123")
|
|
|
|
assert.NoError(t, err)
|
2016-01-26 11:42:44 +00: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 11:14:10 +00:00
|
|
|
}
|
2016-01-26 11:25:51 +00:00
|
|
|
|
|
|
|
func TestNewDNSProviderDNSimpleMissingCredErr(t *testing.T) {
|
2016-01-26 11:42:44 +00:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-01-26 11:25:51 +00:00
|
|
|
_, err := NewDNSProviderDNSimple("", "")
|
|
|
|
assert.EqualError(t, err, "DNSimple credentials missing")
|
2016-01-26 11:42:44 +00:00
|
|
|
restoreDNSimpleEnv()
|
2016-01-26 11:25:51 +00:00
|
|
|
}
|
2016-01-26 14:09:33 +00: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)
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderDNSimple(cflareEmail, cflareAPIKey)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(dnsimpleDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|