1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-20 12:31:12 +02:00
lego/providers/dns/cloudxns/cloudxns_test.go

84 lines
1.8 KiB
Go
Raw Normal View History

2018-05-30 19:53:04 +02:00
package cloudxns
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var (
cxLiveTest bool
cxAPIKey string
cxSecretKey string
cxDomain string
)
func init() {
cxAPIKey = os.Getenv("CLOUDXNS_API_KEY")
cxSecretKey = os.Getenv("CLOUDXNS_SECRET_KEY")
cxDomain = os.Getenv("CLOUDXNS_DOMAIN")
if len(cxAPIKey) > 0 && len(cxSecretKey) > 0 && len(cxDomain) > 0 {
cxLiveTest = true
}
}
func restoreEnv() {
2018-05-30 19:53:04 +02:00
os.Setenv("CLOUDXNS_API_KEY", cxAPIKey)
os.Setenv("CLOUDXNS_SECRET_KEY", cxSecretKey)
}
func TestNewDNSProviderValid(t *testing.T) {
defer restoreEnv()
2018-05-30 19:53:04 +02:00
os.Setenv("CLOUDXNS_API_KEY", "")
os.Setenv("CLOUDXNS_SECRET_KEY", "")
2018-05-30 19:53:04 +02:00
_, err := NewDNSProviderCredentials("123", "123")
assert.NoError(t, err)
}
func TestNewDNSProviderValidEnv(t *testing.T) {
defer restoreEnv()
2018-05-30 19:53:04 +02:00
os.Setenv("CLOUDXNS_API_KEY", "123")
os.Setenv("CLOUDXNS_SECRET_KEY", "123")
2018-05-30 19:53:04 +02:00
_, err := NewDNSProvider()
assert.NoError(t, err)
}
func TestNewDNSProviderMissingCredErr(t *testing.T) {
defer restoreEnv()
2018-05-30 19:53:04 +02:00
os.Setenv("CLOUDXNS_API_KEY", "")
os.Setenv("CLOUDXNS_SECRET_KEY", "")
2018-05-30 19:53:04 +02:00
_, err := NewDNSProvider()
assert.EqualError(t, err, "CloudXNS: some credentials information are missing: CLOUDXNS_API_KEY,CLOUDXNS_SECRET_KEY")
2018-05-30 19:53:04 +02:00
}
func TestCloudXNSPresent(t *testing.T) {
if !cxLiveTest {
t.Skip("skipping live test")
}
provider, err := NewDNSProviderCredentials(cxAPIKey, cxSecretKey)
assert.NoError(t, err)
err = provider.Present(cxDomain, "", "123d==")
assert.NoError(t, err)
}
func TestCloudXNSCleanUp(t *testing.T) {
if !cxLiveTest {
t.Skip("skipping live test")
}
time.Sleep(time.Second * 2)
provider, err := NewDNSProviderCredentials(cxAPIKey, cxSecretKey)
assert.NoError(t, err)
err = provider.CleanUp(cxDomain, "", "123d==")
assert.NoError(t, err)
}