| 1 | package rsyncdconfig_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/gokrazy/rsync/internal/rsyncdconfig" |
| 7 | "github.com/gokrazy/rsync/rsyncd" |
| 8 | "github.com/google/go-cmp/cmp" |
| 9 | ) |
| 10 | |
| 11 | func TestConfig(t *testing.T) { |
| 12 | cfg, err := rsyncdconfig.FromString(` |
| 13 | [[listener]] |
| 14 | rsyncd = "localhost:873" |
| 15 | |
| 16 | [[listener]] |
| 17 | http_monitoring = "localhost:8738" |
| 18 | |
| 19 | [[listener]] |
| 20 | anon_ssh = "localhost:22873" |
| 21 | |
| 22 | [[module]] |
| 23 | name = "interop" |
| 24 | path = "/non/existant/path" |
| 25 | |
| 26 | `) |
| 27 | if err != nil { |
| 28 | t.Fatal(err) |
| 29 | } |
| 30 | |
| 31 | if got, want := len(cfg.Listeners), 3; got != want { |
| 32 | t.Fatalf("unexpected number of listeners: got %d, want %d", got, want) |
| 33 | } |
| 34 | |
| 35 | { |
| 36 | want := []rsyncdconfig.Listener{ |
| 37 | {Rsyncd: "localhost:873"}, |
| 38 | {HTTPMonitoring: "localhost:8738"}, |
| 39 | {AnonSSH: "localhost:22873"}, |
| 40 | } |
| 41 | if diff := cmp.Diff(want, cfg.Listeners); diff != "" { |
| 42 | t.Fatalf("unexpected listener config: diff (-want +got):\n%s", diff) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | { |
| 47 | want := []rsyncd.Module{ |
| 48 | {Name: "interop", Path: "/non/existant/path"}, |
| 49 | } |
| 50 | if diff := cmp.Diff(want, cfg.Modules); diff != "" { |
| 51 | t.Fatalf("unexpected module config: diff (-want +got):\n%s", diff) |
| 52 | } |
| 53 | } |
| 54 | } |