2018-05-30 17:53:04 +00:00
|
|
|
package duckdns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
duckdnsLiveTest bool
|
|
|
|
duckdnsToken string
|
|
|
|
duckdnsDomain string
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
duckdnsToken = os.Getenv("DUCKDNS_TOKEN")
|
|
|
|
duckdnsDomain = os.Getenv("DUCKDNS_DOMAIN")
|
|
|
|
if len(duckdnsToken) > 0 && len(duckdnsDomain) > 0 {
|
|
|
|
duckdnsLiveTest = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-11 15:32:50 +00:00
|
|
|
func restoreEnv() {
|
2018-05-30 17:53:04 +00:00
|
|
|
os.Setenv("DUCKDNS_TOKEN", duckdnsToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreEnv()
|
2018-05-30 17:53:04 +00:00
|
|
|
os.Setenv("DUCKDNS_TOKEN", "123")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-05-30 17:53:04 +00:00
|
|
|
_, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-05-30 17:53:04 +00:00
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreEnv()
|
2018-05-30 17:53:04 +00:00
|
|
|
os.Setenv("DUCKDNS_TOKEN", "")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-05-30 17:53:04 +00:00
|
|
|
_, err := NewDNSProvider()
|
2018-06-11 15:32:50 +00:00
|
|
|
assert.EqualError(t, err, "DuckDNS: some credentials information are missing: DUCKDNS_TOKEN")
|
2018-05-30 17:53:04 +00:00
|
|
|
}
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-05-30 17:53:04 +00:00
|
|
|
func TestLiveDuckdnsPresent(t *testing.T) {
|
|
|
|
if !duckdnsLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
provider, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.Present(duckdnsDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLiveDuckdnsCleanUp(t *testing.T) {
|
|
|
|
if !duckdnsLiveTest {
|
|
|
|
t.Skip("skipping live test")
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(time.Second * 10)
|
|
|
|
|
|
|
|
provider, err := NewDNSProvider()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = provider.CleanUp(duckdnsDomain, "", "123d==")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
}
|