lego/providers/dns/dns_providers_test.go
Thomas Recloux 0792ce9a9f Extract from CLI the name -> DNS provider mapping (#313)
* Extract from CLI the name -> DNS provider mapping

This avoids duplication in lib usage 
Ex : https://github.com/containous/traefik/pull/738#issuecomment-258810469

* Verify that we retrieve the good provider
2016-11-18 14:12:13 +01:00

50 lines
1.2 KiB
Go

package dns
import (
"os"
"reflect"
"testing"
"github.com/stretchr/testify/assert"
"github.com/xenolf/lego/providers/dns/exoscale"
)
var (
apiKey string
apiSecret string
)
func init() {
apiSecret = os.Getenv("EXOSCALE_API_SECRET")
apiKey = os.Getenv("EXOSCALE_API_KEY")
}
func restoreExoscaleEnv() {
os.Setenv("EXOSCALE_API_KEY", apiKey)
os.Setenv("EXOSCALE_API_SECRET", apiSecret)
}
func TestKnownDNSProviderSuccess(t *testing.T) {
os.Setenv("EXOSCALE_API_KEY", "abc")
os.Setenv("EXOSCALE_API_SECRET", "123")
provider, err := NewDNSChallengeProviderByName("exoscale")
assert.NoError(t, err)
assert.NotNil(t, provider)
if reflect.TypeOf(provider) != reflect.TypeOf(&exoscale.DNSProvider{}) {
t.Errorf("Not loaded correct DNS proviver: %v is not *exoscale.DNSProvider", reflect.TypeOf(provider))
}
restoreExoscaleEnv()
}
func TestKnownDNSProviderError(t *testing.T) {
os.Setenv("EXOSCALE_API_KEY", "")
os.Setenv("EXOSCALE_API_SECRET", "")
_, err := NewDNSChallengeProviderByName("exoscale")
assert.Error(t, err)
restoreExoscaleEnv()
}
func TestUnknownDNSProvider(t *testing.T) {
_, err := NewDNSChallengeProviderByName("foobar")
assert.Error(t, err)
}