1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-23 17:21:50 +02:00
lego/providers/dns/joker/joker_test.go

136 lines
2.5 KiB
Go
Raw Normal View History

2019-04-28 14:33:50 +02:00
package joker
import (
2020-10-08 16:52:50 +02:00
"fmt"
"os"
2019-04-28 14:33:50 +02:00
"testing"
"time"
2020-09-02 03:20:01 +02:00
"github.com/go-acme/lego/v4/platform/tester"
2019-04-28 14:33:50 +02:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const envDomain = envNamespace + "DOMAIN"
2020-10-08 16:52:50 +02:00
var envTest = tester.NewEnvTest(EnvAPIKey, EnvUsername, EnvPassword, EnvMode).
WithDomain(envDomain)
2019-04-28 14:33:50 +02:00
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
2020-10-08 16:52:50 +02:00
expected interface{}
2019-04-28 14:33:50 +02:00
}{
{
2020-10-08 16:52:50 +02:00
desc: "mode DMAPI (default)",
2019-04-28 14:33:50 +02:00
envVars: map[string]string{
EnvUsername: "123",
EnvPassword: "123",
2019-04-28 14:33:50 +02:00
},
2020-10-08 16:52:50 +02:00
expected: &dmapiProvider{},
},
{
2020-10-08 16:52:50 +02:00
desc: "mode DMAPI",
envVars: map[string]string{
2020-10-08 16:52:50 +02:00
EnvMode: modeDMAPI,
EnvUsername: "123",
2020-10-08 16:52:50 +02:00
EnvPassword: "123",
},
2020-10-08 16:52:50 +02:00
expected: &dmapiProvider{},
},
{
2020-10-08 16:52:50 +02:00
desc: "mode SVC",
envVars: map[string]string{
2020-10-08 16:52:50 +02:00
EnvMode: modeSVC,
EnvUsername: "123",
EnvPassword: "123",
},
2020-10-08 16:52:50 +02:00
expected: &svcProvider{},
2019-04-28 14:33:50 +02:00
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
defer envTest.RestoreEnv()
envTest.ClearEnv()
envTest.Apply(test.envVars)
2020-10-08 16:52:50 +02:00
fmt.Println(os.Getenv(EnvMode))
2019-04-28 14:33:50 +02:00
p, err := NewDNSProvider()
2020-10-08 16:52:50 +02:00
require.NoError(t, err)
require.NotNil(t, p)
2019-04-28 14:33:50 +02:00
2020-10-08 16:52:50 +02:00
assert.IsType(t, test.expected, p)
2019-04-28 14:33:50 +02:00
})
}
}
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
2020-10-08 16:52:50 +02:00
desc string
mode string
expected interface{}
2019-04-28 14:33:50 +02:00
}{
{
2020-10-08 16:52:50 +02:00
desc: "mode DMAPI (default)",
expected: &dmapiProvider{},
2019-04-28 14:33:50 +02:00
},
{
2020-10-08 16:52:50 +02:00
desc: "mode DMAPI",
mode: modeDMAPI,
expected: &dmapiProvider{},
},
{
2020-10-08 16:52:50 +02:00
desc: "mode SVC",
mode: modeSVC,
expected: &svcProvider{},
2019-04-28 14:33:50 +02:00
},
}
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
2020-10-08 16:52:50 +02:00
config.Username = "123"
config.Password = "123"
config.APIMode = test.mode
2019-04-28 14:33:50 +02:00
p, err := NewDNSProviderConfig(config)
2020-10-08 16:52:50 +02:00
require.NoError(t, err)
require.NotNil(t, p)
2019-04-28 14:33:50 +02:00
2020-10-08 16:52:50 +02:00
assert.IsType(t, test.expected, p)
2019-04-28 14:33:50 +02:00
})
}
}
func TestLivePresent(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}
func TestLiveCleanUp(t *testing.T) {
if !envTest.IsLiveTest() {
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
time.Sleep(2 * time.Second)
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
}