2016-10-18 10:20:15 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 17:32:50 +02:00
|
|
|
func restoreEnv() {
|
2016-10-18 10:20:15 +02:00
|
|
|
os.Setenv("NS1_API_KEY", apiKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
2018-06-11 17:32:50 +02:00
|
|
|
defer restoreEnv()
|
2016-10-18 10:20:15 +02:00
|
|
|
os.Setenv("NS1_API_KEY", "")
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2018-09-15 19:07:24 +02:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = "123"
|
|
|
|
|
|
|
|
_, err := NewDNSProviderConfig(config)
|
2016-10-18 10:20:15 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
2018-06-11 17:32:50 +02:00
|
|
|
defer restoreEnv()
|
2016-10-18 10:20:15 +02:00
|
|
|
os.Setenv("NS1_API_KEY", "")
|
2018-06-11 17:32:50 +02:00
|
|
|
|
2016-10-18 10:20:15 +02:00
|
|
|
_, err := NewDNSProvider()
|
2018-09-15 19:07:24 +02:00
|
|
|
assert.EqualError(t, err, "ns1: some credentials information are missing: NS1_API_KEY")
|
2016-10-18 10:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivePresent(t *testing.T) {
|
|
|
|
if !liveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:07:24 +02:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = apiKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2016-10-18 10:20:15 +02:00
|
|
|
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)
|
|
|
|
|
2018-09-15 19:07:24 +02:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = apiKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2016-10-18 10:20:15 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(domain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|