2016-02-29 02:48:41 +00:00
|
|
|
package dnsimple
|
2016-01-26 11:14:10 +00:00
|
|
|
|
|
|
|
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-03-11 02:46:09 +00:00
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
2016-01-26 11:42:44 +00:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-03-17 20:59:15 +00:00
|
|
|
_, err := NewDNSProviderCredentials("example@example.com", "123")
|
2016-01-26 11:14:10 +00:00
|
|
|
assert.NoError(t, err)
|
2016-01-26 11:42:44 +00:00
|
|
|
restoreDNSimpleEnv()
|
|
|
|
}
|
2016-03-11 02:46:09 +00:00
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
2016-01-26 11:42:44 +00:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "example@example.com")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "123")
|
2016-03-17 20:59:15 +00:00
|
|
|
_, err := NewDNSProvider()
|
2016-01-26 11:42:44 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
restoreDNSimpleEnv()
|
2016-01-26 11:14:10 +00:00
|
|
|
}
|
2016-01-26 11:25:51 +00:00
|
|
|
|
2016-03-11 02:46:09 +00:00
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
2016-01-26 11:42:44 +00:00
|
|
|
os.Setenv("DNSIMPLE_EMAIL", "")
|
|
|
|
os.Setenv("DNSIMPLE_API_KEY", "")
|
2016-03-17 20:59:15 +00:00
|
|
|
_, err := NewDNSProvider()
|
2016-01-26 11:25:51 +00:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2016-03-17 20:59:15 +00:00
|
|
|
provider, err := NewDNSProviderCredentials(dnsimpleEmail, dnsimpleAPIKey)
|
2016-01-26 14:09:33 +00:00
|
|
|
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-03-17 20:59:15 +00:00
|
|
|
provider, err := NewDNSProviderCredentials(dnsimpleEmail, dnsimpleAPIKey)
|
2016-01-26 14:09:33 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(dnsimpleDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|