2018-09-08 15:17:23 +02:00
|
|
|
package alidns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
// "time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
alidnsLiveTest bool
|
|
|
|
alidnsAPIKey string
|
|
|
|
alidnsSecretKey string
|
|
|
|
alidnsDomain string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2018-09-13 16:15:26 +02:00
|
|
|
alidnsAPIKey = os.Getenv("ALICLOUD_ACCESS_KEY")
|
|
|
|
alidnsSecretKey = os.Getenv("ALICLOUD_SECRET_KEY")
|
2018-09-08 15:17:23 +02:00
|
|
|
alidnsDomain = os.Getenv("ALIDNS_DOMAIN")
|
|
|
|
|
|
|
|
if len(alidnsAPIKey) > 0 && len(alidnsSecretKey) > 0 && len(alidnsDomain) > 0 {
|
|
|
|
alidnsLiveTest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func restoreEnv() {
|
2018-09-13 16:15:26 +02:00
|
|
|
os.Setenv("ALICLOUD_ACCESS_KEY", alidnsAPIKey)
|
|
|
|
os.Setenv("ALICLOUD_SECRET_KEY", alidnsSecretKey)
|
2018-09-08 15:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
|
|
|
defer restoreEnv()
|
2018-09-13 16:15:26 +02:00
|
|
|
os.Setenv("ALICLOUD_ACCESS_KEY", "")
|
|
|
|
os.Setenv("ALICLOUD_SECRET_KEY", "")
|
2018-09-08 15:17:23 +02:00
|
|
|
|
2018-09-15 19:07:24 +02:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = "123"
|
|
|
|
config.SecretKey = "123"
|
|
|
|
|
|
|
|
_, err := NewDNSProviderConfig(config)
|
2018-09-08 15:17:23 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
|
|
|
defer restoreEnv()
|
2018-09-13 16:15:26 +02:00
|
|
|
os.Setenv("ALICLOUD_ACCESS_KEY", "123")
|
|
|
|
os.Setenv("ALICLOUD_SECRET_KEY", "123")
|
2018-09-08 15:17:23 +02:00
|
|
|
|
|
|
|
_, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|
|
|
defer restoreEnv()
|
2018-09-13 16:15:26 +02:00
|
|
|
os.Setenv("ALICLOUD_ACCESS_KEY", "")
|
|
|
|
os.Setenv("ALICLOUD_SECRET_KEY", "")
|
2018-09-08 15:17:23 +02:00
|
|
|
|
|
|
|
_, err := NewDNSProvider()
|
2018-09-15 19:07:24 +02:00
|
|
|
assert.EqualError(t, err, "alicloud: some credentials information are missing: ALICLOUD_ACCESS_KEY,ALICLOUD_SECRET_KEY")
|
2018-09-08 15:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCloudXNSPresent(t *testing.T) {
|
|
|
|
if !alidnsLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
2018-09-15 19:07:24 +02:00
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = alidnsAPIKey
|
|
|
|
config.SecretKey = alidnsSecretKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2018-09-08 15:17:23 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(alidnsDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLivednspodCleanUp(t *testing.T) {
|
|
|
|
if !alidnsLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 1)
|
2018-09-15 19:07:24 +02:00
|
|
|
|
|
|
|
config := NewDefaultConfig()
|
|
|
|
config.APIKey = alidnsAPIKey
|
|
|
|
config.SecretKey = alidnsSecretKey
|
|
|
|
|
|
|
|
provider, err := NewDNSProviderConfig(config)
|
2018-09-08 15:17:23 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.CleanUp(alidnsDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|