forked from TrueCloudLab/lego
bba134ce87
* 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).
105 lines
2.2 KiB
Go
105 lines
2.2 KiB
Go
package gcloud
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/oauth2/google"
|
|
"google.golang.org/api/dns/v1"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var (
|
|
gcloudLiveTest bool
|
|
gcloudProject string
|
|
gcloudDomain string
|
|
)
|
|
|
|
func init() {
|
|
gcloudProject = os.Getenv("GCE_PROJECT")
|
|
gcloudDomain = os.Getenv("GCE_DOMAIN")
|
|
_, err := google.DefaultClient(context.Background(), dns.NdevClouddnsReadwriteScope)
|
|
if err == nil && len(gcloudProject) > 0 && len(gcloudDomain) > 0 {
|
|
gcloudLiveTest = true
|
|
}
|
|
}
|
|
|
|
func restoreEnv() {
|
|
os.Setenv("GCE_PROJECT", gcloudProject)
|
|
}
|
|
|
|
func TestNewDNSProviderValid(t *testing.T) {
|
|
if !gcloudLiveTest {
|
|
t.Skip("skipping live test (requires credentials)")
|
|
}
|
|
|
|
defer restoreEnv()
|
|
os.Setenv("GCE_PROJECT", "")
|
|
|
|
_, err := NewDNSProviderCredentials("my-project")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestNewDNSProviderValidEnv(t *testing.T) {
|
|
if !gcloudLiveTest {
|
|
t.Skip("skipping live test (requires credentials)")
|
|
}
|
|
|
|
defer restoreEnv()
|
|
os.Setenv("GCE_PROJECT", "my-project")
|
|
|
|
_, err := NewDNSProvider()
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestNewDNSProviderMissingCredErr(t *testing.T) {
|
|
defer restoreEnv()
|
|
os.Setenv("GCE_PROJECT", "")
|
|
|
|
_, err := NewDNSProvider()
|
|
assert.EqualError(t, err, "googlecloud: project name missing")
|
|
}
|
|
|
|
func TestLiveGoogleCloudPresent(t *testing.T) {
|
|
if !gcloudLiveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
provider, err := NewDNSProviderCredentials(gcloudProject)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.Present(gcloudDomain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLiveGoogleCloudPresentMultiple(t *testing.T) {
|
|
if !gcloudLiveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
provider, err := NewDNSProviderCredentials(gcloudProject)
|
|
assert.NoError(t, err)
|
|
|
|
// Check that we're able to create multiple entries
|
|
err = provider.Present(gcloudDomain, "1", "123d==")
|
|
assert.NoError(t, err)
|
|
err = provider.Present(gcloudDomain, "2", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestLiveGoogleCloudCleanUp(t *testing.T) {
|
|
if !gcloudLiveTest {
|
|
t.Skip("skipping live test")
|
|
}
|
|
|
|
time.Sleep(time.Second * 1)
|
|
|
|
provider, err := NewDNSProviderCredentials(gcloudProject)
|
|
assert.NoError(t, err)
|
|
|
|
err = provider.CleanUp(gcloudDomain, "", "123d==")
|
|
assert.NoError(t, err)
|
|
}
|