feat: change detector
This commit is contained in:
65
pkg/config/config_test.go
Normal file
65
pkg/config/config_test.go
Normal file
@@ -0,0 +1,65 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user