2016-11-14 10:41:37 +00:00
|
|
|
package dnspod
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2018-06-11 15:32:50 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2016-11-14 10:41:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
dnspodLiveTest bool
|
|
|
|
dnspodAPIKey string
|
|
|
|
dnspodDomain string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
dnspodAPIKey = os.Getenv("DNSPOD_API_KEY")
|
|
|
|
dnspodDomain = os.Getenv("DNSPOD_DOMAIN")
|
|
|
|
if len(dnspodAPIKey) > 0 && len(dnspodDomain) > 0 {
|
|
|
|
dnspodLiveTest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 15:32:50 +00:00
|
|
|
func restoreEnv() {
|
2016-11-14 10:41:37 +00:00
|
|
|
os.Setenv("DNSPOD_API_KEY", dnspodAPIKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreEnv()
|
2016-11-14 10:41:37 +00:00
|
|
|
os.Setenv("DNSPOD_API_KEY", "")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-09-15 17:07:24 +00:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.LoginToken = "123"
|
|
|
|
|
|
|
|
_, err := NewDNSProviderConfig(config)
|
2016-11-14 10:41:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreEnv()
|
2016-11-14 10:41:37 +00:00
|
|
|
os.Setenv("DNSPOD_API_KEY", "123")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2016-11-14 10:41:37 +00:00
|
|
|
_, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreEnv()
|
2016-11-14 10:41:37 +00:00
|
|
|
os.Setenv("DNSPOD_API_KEY", "")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2016-11-14 10:41:37 +00:00
|
|
|
_, err := NewDNSProvider()
|
2018-09-15 17:07:24 +00:00
|
|
|
assert.EqualError(t, err, "dnspod: some credentials information are missing: DNSPOD_API_KEY")
|
2016-11-14 10:41:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivednspodPresent(t *testing.T) {
|
|
|
|
if !dnspodLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-09-15 17:07:24 +00:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.LoginToken = dnspodAPIKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2016-11-14 10:41:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(dnspodDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivednspodCleanUp(t *testing.T) {
|
|
|
|
if !dnspodLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
|
2018-09-15 17:07:24 +00:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.LoginToken = dnspodAPIKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2016-11-14 10:41:37 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(dnspodDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|