diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-11-16 19:28:52 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-16 19:28:52 -0500 |
commit | 0135904f7d3e1c0e763adaefe267c736616e3d26 (patch) | |
tree | c27be7588f98eaea62e0bd0c0087f2b348da9738 /vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go | |
parent | 0b296dd8c2aefefe89787be5cc627d44cf431150 (diff) | |
download | chat-0135904f7d3e1c0e763adaefe267c736616e3d26.tar.gz chat-0135904f7d3e1c0e763adaefe267c736616e3d26.tar.bz2 chat-0135904f7d3e1c0e763adaefe267c736616e3d26.zip |
Upgrading server dependancies (#4566)
Diffstat (limited to 'vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go')
-rw-r--r-- | vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go b/vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go new file mode 100644 index 000000000..db55f578a --- /dev/null +++ b/vendor/github.com/xenolf/lego/providers/dns/azure/azure_test.go @@ -0,0 +1,89 @@ +package azure + +import ( + "os" + "testing" + "time" + + "github.com/stretchr/testify/assert" +) + +var ( + azureLiveTest bool + azureClientID string + azureClientSecret string + azureSubscriptionID string + azureTenantID string + azureResourceGroup string + azureDomain string +) + +func init() { + azureClientID = os.Getenv("AZURE_CLIENT_ID") + azureClientSecret = os.Getenv("AZURE_CLIENT_SECRET") + azureSubscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID") + azureTenantID = os.Getenv("AZURE_TENANT_ID") + azureResourceGroup = os.Getenv("AZURE_RESOURCE_GROUP") + azureDomain = os.Getenv("AZURE_DOMAIN") + if len(azureClientID) > 0 && len(azureClientSecret) > 0 { + azureLiveTest = true + } +} + +func restoreAzureEnv() { + os.Setenv("AZURE_CLIENT_ID", azureClientID) + os.Setenv("AZURE_SUBSCRIPTION_ID", azureSubscriptionID) +} + +func TestNewDNSProviderValid(t *testing.T) { + if !azureLiveTest { + t.Skip("skipping live test (requires credentials)") + } + os.Setenv("AZURE_CLIENT_ID", "") + _, err := NewDNSProviderCredentials(azureClientID, azureClientSecret, azureSubscriptionID, azureTenantID, azureResourceGroup) + assert.NoError(t, err) + restoreAzureEnv() +} + +func TestNewDNSProviderValidEnv(t *testing.T) { + if !azureLiveTest { + t.Skip("skipping live test (requires credentials)") + } + os.Setenv("AZURE_CLIENT_ID", "other") + _, err := NewDNSProvider() + assert.NoError(t, err) + restoreAzureEnv() +} + +func TestNewDNSProviderMissingCredErr(t *testing.T) { + os.Setenv("AZURE_SUBSCRIPTION_ID", "") + _, err := NewDNSProvider() + assert.EqualError(t, err, "Azure configuration missing") + restoreAzureEnv() +} + +func TestLiveAzurePresent(t *testing.T) { + if !azureLiveTest { + t.Skip("skipping live test") + } + + provider, err := NewDNSProviderCredentials(azureClientID, azureClientSecret, azureSubscriptionID, azureTenantID, azureResourceGroup) + assert.NoError(t, err) + + err = provider.Present(azureDomain, "", "123d==") + assert.NoError(t, err) +} + +func TestLiveAzureCleanUp(t *testing.T) { + if !azureLiveTest { + t.Skip("skipping live test") + } + + provider, err := NewDNSProviderCredentials(azureClientID, azureClientSecret, azureSubscriptionID, azureTenantID, azureResourceGroup) + time.Sleep(time.Second * 1) + + assert.NoError(t, err) + + err = provider.CleanUp(azureDomain, "", "123d==") + assert.NoError(t, err) +} |