lego/providers/dns/vultr/vultr_test.go

69 lines
1.2 KiB
Go
Raw Normal View History

2016-03-20 23:23:37 +00:00
package vultr
import (
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
2016-03-20 23:23:37 +00:00
)
var (
liveTest bool
apiKey string
domain string
)
func init() {
apiKey = os.Getenv("VULTR_API_KEY")
domain = os.Getenv("VULTR_TEST_DOMAIN")
liveTest = len(apiKey) > 0 && len(domain) > 0
}
func restoreEnv() {
os.Setenv("VULTR_API_KEY", apiKey)
}
func TestNewDNSProviderValidEnv(t *testing.T) {
defer restoreEnv()
os.Setenv("VULTR_API_KEY", "123")
2016-03-20 23:23:37 +00:00
_, err := NewDNSProvider()
require.NoError(t, err)
2016-03-20 23:23:37 +00:00
}
func TestNewDNSProviderMissingCredErr(t *testing.T) {
defer restoreEnv()
os.Setenv("VULTR_API_KEY", "")
2016-03-20 23:23:37 +00:00
_, err := NewDNSProvider()
assert.EqualError(t, err, "vultr: some credentials information are missing: VULTR_API_KEY")
2016-03-20 23:23:37 +00:00
}
func TestLivePresent(t *testing.T) {
if !liveTest {
t.Skip("skipping live test")
}
provider, err := NewDNSProvider()
require.NoError(t, err)
2016-03-20 23:23:37 +00:00
err = provider.Present(domain, "", "123d==")
require.NoError(t, err)
2016-03-20 23:23:37 +00:00
}
func TestLiveCleanUp(t *testing.T) {
if !liveTest {
t.Skip("skipping live test")
}
time.Sleep(time.Second * 1)
provider, err := NewDNSProvider()
require.NoError(t, err)
2016-03-20 23:23:37 +00:00
err = provider.CleanUp(domain, "", "123d==")
require.NoError(t, err)
2016-03-20 23:23:37 +00:00
}