lego/acme/dns_challenge_dnsimple_test.go

47 lines
1.1 KiB
Go
Raw Normal View History

package acme
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var (
dnsimpleEmail string
dnsimpleAPIKey string
)
func init() {
dnsimpleEmail = os.Getenv("DNSIMPLE_EMAIL")
dnsimpleAPIKey = os.Getenv("DNSIMPLE_API_KEY")
}
func restoreDNSimpleEnv() {
os.Setenv("DNSIMPLE_EMAIL", dnsimpleEmail)
os.Setenv("DNSIMPLE_API_KEY", dnsimpleAPIKey)
}
func TestNewDNSProviderDNSimpleValid(t *testing.T) {
os.Setenv("DNSIMPLE_EMAIL", "")
os.Setenv("DNSIMPLE_API_KEY", "")
_, err := NewDNSProviderDNSimple("example@example.com", "123")
assert.NoError(t, err)
restoreDNSimpleEnv()
}
func TestNewDNSProviderDNSimpleValidEnv(t *testing.T) {
os.Setenv("DNSIMPLE_EMAIL", "example@example.com")
os.Setenv("DNSIMPLE_API_KEY", "123")
_, err := NewDNSProviderDNSimple("", "")
assert.NoError(t, err)
restoreDNSimpleEnv()
}
func TestNewDNSProviderDNSimpleMissingCredErr(t *testing.T) {
os.Setenv("DNSIMPLE_EMAIL", "")
os.Setenv("DNSIMPLE_API_KEY", "")
_, err := NewDNSProviderDNSimple("", "")
assert.EqualError(t, err, "DNSimple credentials missing")
restoreDNSimpleEnv()
}