Files
realDynDNS/pkg/config/config_test.go
2024-04-01 11:44:53 +02:00

66 lines
1.4 KiB
Go

package config
import (
"testing"
)
func TestLoad(t *testing.T) {
t.Run("Can find file", testLoadCanFindFile())
t.Run("Cannot find file", testLoadCannotFindFile())
t.Run("Unmarshals from direct input", testLoadUnmarshalsFromDirectInput())
}
func testLoadCanFindFile() func(t *testing.T) {
return func(t *testing.T) {
c := Config{}
err := c.Load("./__mocks__/testLoadCanFindFile.yaml")
want := c.DNSProvider.Type == "ionos" && c.ExternalIPProvider.Type == "plain"
if !want || err != nil {
t.Fatalf("DnsProviderName couldn't be properly loaded or unmarshaled, Load() = %v, want %v", err, want)
}
}
}
func testLoadCannotFindFile() func(t *testing.T) {
return func(t *testing.T) {
c := Config{}
err := c.Load("nonexistent.yaml")
want := err != nil
if !want {
t.Fatalf("Config didn't throw an error")
}
}
}
func testLoadUnmarshalsFromDirectInput() func(t *testing.T) {
return func(t *testing.T) {
c := Config{}
err := c.Load(`---
ip_provider:
type: plain
config:
url: https://ifconfig.me
dns_provider:
type: ionos
config:
api_key: exampleAPIKey
base_url: https://example.com
domains:
- tld: example.com
subdomains:
- "@"
- www
check_interval: 0 0 0/6 * * * *`)
want := c.DNSProvider.Type == "ionos" && c.ExternalIPProvider.Type == "plain"
if !want || err != nil {
t.Fatalf("DnsProviderName couldn't be properly loaded or unmarshaled, Load() = %v, want %v", err, want)
}
}
}