2019-03-11 16:56:48 +00:00
|
|
|
package dns
|
2016-11-18 13:12:13 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-09-02 01:20:01 +00:00
|
|
|
"github.com/go-acme/lego/v4/platform/tester"
|
|
|
|
"github.com/go-acme/lego/v4/providers/dns/exec"
|
2016-11-18 13:12:13 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2018-10-12 17:29:18 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
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")
|
2023-10-31 13:08:50 +00:00
|
|
|
require.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")
|
2023-10-31 13:08:50 +00:00
|
|
|
require.Error(t, err)
|
2018-10-18 20:32:00 +00:00
|
|
|
assert.Nil(t, provider)
|
2016-11-18 13:12:13 +00:00
|
|
|
}
|