2016-11-18 13:12:13 +00:00
|
|
|
package dns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"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) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreExoscaleEnv()
|
2016-11-18 13:12:13 +00:00
|
|
|
os.Setenv("EXOSCALE_API_KEY", "abc")
|
|
|
|
os.Setenv("EXOSCALE_API_SECRET", "123")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2016-11-18 13:12:13 +00:00
|
|
|
provider, err := NewDNSChallengeProviderByName("exoscale")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, provider)
|
2018-06-11 15:32:50 +00:00
|
|
|
|
|
|
|
assert.IsType(t, &exoscale.DNSProvider{}, provider, "Not loaded correct DNS provider")
|
2016-11-18 13:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestKnownDNSProviderError(t *testing.T) {
|
2018-06-11 15:32:50 +00:00
|
|
|
defer restoreExoscaleEnv()
|
2016-11-18 13:12:13 +00:00
|
|
|
os.Setenv("EXOSCALE_API_KEY", "")
|
|
|
|
os.Setenv("EXOSCALE_API_SECRET", "")
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2016-11-18 13:12:13 +00:00
|
|
|
_, err := NewDNSChallengeProviderByName("exoscale")
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnknownDNSProvider(t *testing.T) {
|
|
|
|
_, err := NewDNSChallengeProviderByName("foobar")
|
|
|
|
assert.Error(t, err)
|
|
|
|
}
|