| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | func TestDefaults(t *testing.T) { |
| 11 | c, err := Load(filepath.Join(t.TempDir(), "geen.yml")) |
| 12 | if err != nil { |
| 13 | t.Fatal(err) |
| 14 | } |
| 15 | if c.ArchiveInterval.Duration != 24*time.Hour || c.RetentionDays != 30 || c.RateLimitKiB != 1024 || c.Listen != "0.0.0.0:8790" { |
| 16 | t.Fatalf("%+v", c) |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | func TestLoad(t *testing.T) { |
| 21 | p := filepath.Join(t.TempDir(), "c.yml") |
| 22 | _ = os.WriteFile(p, []byte("archive_interval: 7d\nretention_days: -1\nrate_limit_kib: -1\npublic_url: http://b:1\n"), 0o600) |
| 23 | c, err := Load(p) |
| 24 | if err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | if c.ArchiveInterval.Duration != 7*24*time.Hour || c.RetentionDays != 0 || c.RateLimitKiB != 0 { |
| 28 | t.Fatalf("%+v", c) |
| 29 | } |
| 30 | _ = os.WriteFile(p, []byte("public_url: ftp://x\n"), 0o600) |
| 31 | if _, err := Load(p); err == nil { |
| 32 | t.Fatal("ftp geaccepteerd") |
| 33 | } |
| 34 | _ = os.WriteFile(p, []byte("archive_interval: soms\n"), 0o600) |
| 35 | if _, err := Load(p); err == nil { |
| 36 | t.Fatal("ongeldige duur geaccepteerd") |
| 37 | } |
| 38 | if _, err := os.Stat(p); err != nil { |
| 39 | t.Fatal(err) |
| 40 | } |
| 41 | if Example() == "" { |
| 42 | t.Fatal("geen voorbeeld") |
| 43 | } |
| 44 | } |