1
0
mirror of https://github.com/go-acme/lego.git synced 2024-12-22 16:53:17 +02:00
lego/providers/dns/hostingde/hostingde_test.go

140 lines
2.7 KiB
Go
Raw Permalink Normal View History

2019-03-11 18:56:48 +02:00
package hostingde
2018-09-15 23:25:14 +02:00
import (
"testing"
"time"
2020-09-02 03:20:01 +02:00
"github.com/go-acme/lego/v4/platform/tester"
2018-09-15 23:25:14 +02:00
"github.com/stretchr/testify/require"
)
const envDomain = envNamespace + "DOMAIN"
var envTest = tester.NewEnvTest(
EnvAPIKey,
EnvZoneName).
WithDomain(envDomain)
2018-09-15 23:25:14 +02:00
func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
desc string
envVars map[string]string
expected string
}{
{
desc: "success",
envVars: map[string]string{
EnvAPIKey: "123",
EnvZoneName: "example.org",
},
},
{
desc: "missing credentials",
envVars: map[string]string{
EnvAPIKey: "",
EnvZoneName: "",
},
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY",
},
{
desc: "missing access key",
envVars: map[string]string{
EnvAPIKey: "",
EnvZoneName: "456",
},
expected: "hostingde: some credentials information are missing: HOSTINGDE_API_KEY",
},
}
2018-09-15 23:25:14 +02:00
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
defer envTest.RestoreEnv()
envTest.ClearEnv()
envTest.Apply(test.envVars)
p, err := NewDNSProvider()
2021-03-04 21:16:59 +02:00
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.recordIDs)
} else {
require.EqualError(t, err, test.expected)
}
})
}
2018-09-15 23:25:14 +02:00
}
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
apiKey string
zoneName string
expected string
}{
{
desc: "success",
apiKey: "123",
zoneName: "example.org",
},
{
desc: "missing credentials",
expected: "hostingde: API key missing",
},
{
desc: "missing api key",
zoneName: "456",
expected: "hostingde: API key missing",
},
}
2018-09-15 23:25:14 +02:00
for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
config.APIKey = test.apiKey
config.ZoneName = test.zoneName
p, err := NewDNSProviderConfig(config)
2021-03-04 21:16:59 +02:00
if test.expected == "" {
require.NoError(t, err)
require.NotNil(t, p)
require.NotNil(t, p.config)
require.NotNil(t, p.recordIDs)
} else {
require.EqualError(t, err, test.expected)
}
})
}
2018-09-15 23:25:14 +02:00
}
func TestLivePresent(t *testing.T) {
if !envTest.IsLiveTest() {
2018-09-15 23:25:14 +02:00
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
2018-09-15 23:25:14 +02:00
require.NoError(t, err)
err = provider.Present(envTest.GetDomain(), "", "123d==")
require.NoError(t, err)
2018-09-15 23:25:14 +02:00
}
func TestLiveCleanUp(t *testing.T) {
if !envTest.IsLiveTest() {
2018-09-15 23:25:14 +02:00
t.Skip("skipping live test")
}
envTest.RestoreEnv()
provider, err := NewDNSProvider()
require.NoError(t, err)
2018-09-15 23:25:14 +02:00
time.Sleep(2 * time.Second)
2018-09-15 23:25:14 +02:00
err = provider.CleanUp(envTest.GetDomain(), "", "123d==")
2018-09-15 23:25:14 +02:00
require.NoError(t, err)
}