lego/providers/dns/pdns/pdns_test.go
Ludovic Fernandez bba134ce87
Allow to configure TTL, interval and timeout (#634)
* feat: add GetOrDefaultXXX methods.
* refactor: configuration (alidns).
* refactor: configuration (azure).
* refactor: configuration (auroradns).
* refactor: configuration (bluecat).
* refactor: configuration (cloudflare).
* refactor: configuration (digitalocean).
* refactor: configuration (dnsimple).
* refactor: configuration (dnmadeeasy).
* refactor: configuration (dnspod).
* refactor: configuration (duckdns).
* refactor: configuration (dyn).
* refactor: configuration (exoscale).
* refactor: configuration (fastdns).
* refactor: configuration (gandi).
* refactor: configuration (gandiv5).
* refactor: configuration (gcloud).
* refactor: configuration (glesys).
* refactor: configuration (godaddy).
* refactor: configuration (iij).
* refactor: configuration (lightsail).
* refactor: configuration (linode).
* refactor: configuration (namecheap).
* refactor: configuration (namedotcom).
* refactor: configuration (netcup).
* refactor: configuration (nifcloud).
* refactor: configuration (ns1).
* refactor: configuration (otc).
* refactor: configuration (ovh).
* refactor: configuration (pdns).
* refactor: configuration (rackspace).
* refactor: configuration (rfc2136).
* refactor: configuration (route53).
* refactor: configuration (sakuracloud).
* refactor: configuration (vegadns).
* refactor: configuration (vultr).
2018-09-15 19:07:24 +02:00

93 lines
2 KiB
Go

package pdns
import (
"net/url"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var (
pdnsLiveTest bool
pdnsURL *url.URL
pdnsURLStr string
pdnsAPIKey string
pdnsDomain string
)
func init() {
pdnsURLStr = os.Getenv("PDNS_API_URL")
pdnsURL, _ = url.Parse(pdnsURLStr)
pdnsAPIKey = os.Getenv("PDNS_API_KEY")
pdnsDomain = os.Getenv("PDNS_DOMAIN")
if len(pdnsURLStr) > 0 && len(pdnsAPIKey) > 0 && len(pdnsDomain) > 0 {
pdnsLiveTest = true
}
}
func restoreEnv() {
os.Setenv("PDNS_API_URL", pdnsURLStr)
os.Setenv("PDNS_API_KEY", pdnsAPIKey)
}
func TestNewDNSProviderValid(t *testing.T) {
defer restoreEnv()
os.Setenv("PDNS_API_URL", "")
os.Setenv("PDNS_API_KEY", "")
tmpURL, _ := url.Parse("http://localhost:8081")
config := NewDefaultConfig()
config.Host = tmpURL
config.APIKey = "123"
_, err := NewDNSProviderConfig(config)
assert.NoError(t, err)
}
func TestNewDNSProviderValidEnv(t *testing.T) {
defer restoreEnv()
os.Setenv("PDNS_API_URL", "http://localhost:8081")
os.Setenv("PDNS_API_KEY", "123")
_, err := NewDNSProvider()
assert.NoError(t, err)
}
func TestNewDNSProviderMissingHostErr(t *testing.T) {
defer restoreEnv()
os.Setenv("PDNS_API_URL", "")
os.Setenv("PDNS_API_KEY", "123")
_, err := NewDNSProvider()
assert.EqualError(t, err, "pdns: some credentials information are missing: PDNS_API_URL")
}
func TestNewDNSProviderMissingKeyErr(t *testing.T) {
defer restoreEnv()
os.Setenv("PDNS_API_URL", pdnsURLStr)
os.Setenv("PDNS_API_KEY", "")
_, err := NewDNSProvider()
assert.EqualError(t, err, "pdns: some credentials information are missing: PDNS_API_KEY,PDNS_API_URL")
}
func TestPdnsPresentAndCleanup(t *testing.T) {
if !pdnsLiveTest {
t.Skip("skipping live test")
}
config := NewDefaultConfig()
config.Host = pdnsURL
config.APIKey = pdnsAPIKey
provider, err := NewDNSProviderConfig(config)
assert.NoError(t, err)
err = provider.Present(pdnsDomain, "", "123d==")
assert.NoError(t, err)
err = provider.CleanUp(pdnsDomain, "", "123d==")
assert.NoError(t, err)
}