package config import ( "os" "path/filepath" "testing" "time" ) func TestExampleParses(t *testing.T) { path := filepath.Join(t.TempDir(), "jarl.yaml") os.WriteFile(path, []byte(Example), 0o644) c, err := Load(path, false) if err != nil { t.Fatal(err) } d := Default() if c.BIND.ZoneDir != d.BIND.ZoneDir || time.Duration(c.Session.IdleTimeout) != 2*time.Hour || c.Listen[0] != "127.0.0.1:8053" { t.Errorf("example differs from defaults: %+v", c) } } func TestLoad(t *testing.T) { dir := t.TempDir() path := filepath.Join(dir, "jarl.yaml") os.WriteFile(path, []byte("listen: [\"0.0.0.0:8443\"]\ntls: {cert_file: /a, key_file: /b}\ntrusted_proxies: [10.0.0.1, 192.168.0.0/16]\nsession: {lifetime: 1d}\n"), 0o644) c, err := Load(path, false) if err != nil { t.Fatal(err) } if time.Duration(c.Session.Lifetime) != 24*time.Hour || len(c.Proxies()) != 2 || c.BIND.FileGroup != "bind" { t.Errorf("config = %+v", c) } os.WriteFile(path, []byte("lisen: []\n"), 0o644) if _, err := Load(path, false); err == nil { t.Error("unknown field accepted") } os.WriteFile(path, []byte("tls: {cert_file: /a}\n"), 0o644) if _, err := Load(path, false); err == nil { t.Error("half TLS config accepted") } if _, err := Load(filepath.Join(dir, "missing.yaml"), true); err != nil { t.Errorf("missing file with allowMissing: %v", err) } }