1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-14 06:06:10 +02:00
lego/providers/dns/dnspod/dnspod_test.go

77 lines
1.5 KiB
Go
Raw Normal View History

2016-11-14 12:41:37 +02:00
package dnspod
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
2016-11-14 12:41:37 +02: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
}
}
func restoreEnv() {
2016-11-14 12:41:37 +02:00
os.Setenv("DNSPOD_API_KEY", dnspodAPIKey)
}
func TestNewDNSProviderValid(t *testing.T) {
defer restoreEnv()
2016-11-14 12:41:37 +02:00
os.Setenv("DNSPOD_API_KEY", "")
2016-11-14 12:41:37 +02:00
_, err := NewDNSProviderCredentials("123")
assert.NoError(t, err)
}
func TestNewDNSProviderValidEnv(t *testing.T) {
defer restoreEnv()
2016-11-14 12:41:37 +02:00
os.Setenv("DNSPOD_API_KEY", "123")
2016-11-14 12:41:37 +02:00
_, err := NewDNSProvider()
assert.NoError(t, err)
}
func TestNewDNSProviderMissingCredErr(t *testing.T) {
defer restoreEnv()
2016-11-14 12:41:37 +02:00
os.Setenv("DNSPOD_API_KEY", "")
2016-11-14 12:41:37 +02:00
_, err := NewDNSProvider()
assert.EqualError(t, err, "DNSPod: some credentials information are missing: DNSPOD_API_KEY")
2016-11-14 12:41:37 +02:00
}
func TestLivednspodPresent(t *testing.T) {
if !dnspodLiveTest {
t.Skip("skipping live test")
}
provider, err := NewDNSProviderCredentials(dnspodAPIKey)
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)
provider, err := NewDNSProviderCredentials(dnspodAPIKey)
assert.NoError(t, err)
err = provider.CleanUp(dnspodDomain, "", "123d==")
assert.NoError(t, err)
}