bba134ce87
* feat: add GetOrDefaultXXX methods. * refactor: configuration (alidns). * refactor: configuration (azure). * refactor: configuration (auroradns). * refactor: configuration (bluecat). * refactor: configuration (cloudflare). * refactor: configuration (digitalocean). * refactor: configuration (dnsimple). * refactor: configuration (dnmadeeasy). * refactor: configuration (dnspod). * refactor: configuration (duckdns). * refactor: configuration (dyn). * refactor: configuration (exoscale). * refactor: configuration (fastdns). * refactor: configuration (gandi). * refactor: configuration (gandiv5). * refactor: configuration (gcloud). * refactor: configuration (glesys). * refactor: configuration (godaddy). * refactor: configuration (iij). * refactor: configuration (lightsail). * refactor: configuration (linode). * refactor: configuration (namecheap). * refactor: configuration (namedotcom). * refactor: configuration (netcup). * refactor: configuration (nifcloud). * refactor: configuration (ns1). * refactor: configuration (otc). * refactor: configuration (ovh). * refactor: configuration (pdns). * refactor: configuration (rackspace). * refactor: configuration (rfc2136). * refactor: configuration (route53). * refactor: configuration (sakuracloud). * refactor: configuration (vegadns). * refactor: configuration (vultr).
78 lines
1.4 KiB
Go
78 lines
1.4 KiB
Go
package ns1
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
liveTest bool
|
|
apiKey string
|
|
domain string
|
|
)
|
|
|
|
func init() {
|
|
apiKey = os.Getenv("NS1_API_KEY")
|
|
domain = os.Getenv("NS1_DOMAIN")
|
|
if len(apiKey) > 0 && len(domain) > 0 {
|
|
liveTest = true
|
|
}
|
|
}
|
|
|
|
func restoreEnv() {
|
|
os.Setenv("NS1_API_KEY", apiKey)
|
|
}
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
|
defer restoreEnv()
|
|
os.Setenv("NS1_API_KEY", "")
|
|
|
|
config := NewDefaultConfig()
|
|
config.APIKey = "123"
|
|
|
|
_, err := NewDNSProviderConfig(config)
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|
defer restoreEnv()
|
|
os.Setenv("NS1_API_KEY", "")
|
|
|
|
_, err := NewDNSProvider()
|
|
assert.EqualError(t, err, "ns1: some credentials information are missing: NS1_API_KEY")
|
|
}
|
|
|
|
func TestLivePresent(t *testing.T) {
|
|
if !liveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
config := NewDefaultConfig()
|
|
config.APIKey = apiKey
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.Present(domain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLiveCleanUp(t *testing.T) {
|
|
if !liveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
config := NewDefaultConfig()
|
|
config.APIKey = apiKey
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.CleanUp(domain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|