2019-03-11 15:54:35 +00:00
|
|
|
package dns // import "github.com/xenolf/lego/providers/dns"
|
2016-11-18 13:12:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-12 17:29:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2018-10-18 20:32:00 +00:00
|
|
|
"github.com/xenolf/lego/platform/tester"
|
|
|
|
"github.com/xenolf/lego/providers/dns/exec"
|
2016-11-18 13:12:13 +00:00
|
|
|
)
|
|
|
|
|
2018-10-18 20:32:00 +00:00
|
|
|
var envTest = tester.NewEnvTest("EXEC_PATH")
|
2016-11-18 13:12:13 +00:00
|
|
|
|
|
|
|
func TestKnownDNSProviderSuccess(t *testing.T) {
|
2018-10-18 20:32:00 +00:00
|
|
|
defer envTest.RestoreEnv()
|
|
|
|
envTest.Apply(map[string]string{
|
|
|
|
"EXEC_PATH": "abc",
|
|
|
|
})
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-10-18 20:32:00 +00:00
|
|
|
provider, err := NewDNSChallengeProviderByName("exec")
|
2018-10-12 17:29:18 +00:00
|
|
|
require.NoError(t, err)
|
2016-11-18 13:12:13 +00:00
|
|
|
assert.NotNil(t, provider)
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-10-18 20:32:00 +00:00
|
|
|
assert.IsType(t, &exec.DNSProvider{}, provider, "The loaded DNS provider doesn't have the expected type.")
|
2016-11-18 13:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestKnownDNSProviderError(t *testing.T) {
|
2018-10-18 20:32:00 +00:00
|
|
|
defer envTest.RestoreEnv()
|
|
|
|
envTest.ClearEnv()
|
2018-06-11 15:32:50 +00:00
|
|
|
|
2018-10-18 20:32:00 +00:00
|
|
|
provider, err := NewDNSChallengeProviderByName("exec")
|
2016-11-18 13:12:13 +00:00
|
|
|
assert.Error(t, err)
|
2018-10-18 20:32:00 +00:00
|
|
|
assert.Nil(t, provider)
|
2016-11-18 13:12:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnknownDNSProvider(t *testing.T) {
|
2018-10-18 20:32:00 +00:00
|
|
|
provider, err := NewDNSChallengeProviderByName("foobar")
|
2016-11-18 13:12:13 +00:00
|
|
|
assert.Error(t, err)
|
2018-10-18 20:32:00 +00:00
|
|
|
assert.Nil(t, provider)
|
2016-11-18 13:12:13 +00:00
|
|
|
}
|