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