package syncengine import "testing" func TestIsProgressOnlyLine(t *testing.T) { cases := []struct { name string line string expect bool }{ {"per-file progress 0%", " 32,768 0% 0.00kB/s 0:00:00", true}, {"per-file progress 7%", " 2,260,893,696 7% 51.14MB/s 0:08:45", true}, {"per-file progress with xfr suffix", " 67,141,632 0% 32.02MB/s 0:15:06 (xfr#1, to-chk=4/10)", true}, {"filename line", "Dragon Ball Sleeping Princess in Devil's Castle (1987)/", false}, {"sending incremental file list header", "sending incremental file list", false}, {"sent bytes stats", "sent 123,456 bytes received 789 bytes 12.34kB/s", false}, {"total size stats", "total size is 999,999,999 speedup is 1.23", false}, {"Number of files stats", "Number of files: 10", false}, {"building file list", "building file list ...", false}, {"empty line", "", false}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := isProgressOnlyLine(tc.line) if got != tc.expect { t.Errorf("isProgressOnlyLine(%q) = %v, want %v", tc.line, got, tc.expect) } }) } } func TestParseProgressFields(t *testing.T) { cases := []struct { name string line string wantPct int wantSpeedBps int64 wantEtaSeconds int wantXfrDone int wantXfrTotal int }{ { name: "progress 0% with kB/s", line: " 32,768 0% 0.00kB/s 0:00:00", wantPct: 0, wantSpeedBps: 0, wantEtaSeconds: 0, }, { name: "progress 7% with MB/s", line: " 2,260,893,696 7% 51.14MB/s 0:08:45", wantPct: 7, wantSpeedBps: 51_140_000, wantEtaSeconds: 8*60 + 45, }, { name: "progress with xfr suffix", line: " 67,141,632 0% 32.02MB/s 0:15:06 (xfr#1, to-chk=4/10)", wantPct: 0, wantSpeedBps: 32_020_000, wantEtaSeconds: 15*60 + 6, wantXfrDone: 1, wantXfrTotal: 10, }, { name: "progress with GB/s", line: " 1,234,567,890 50% 1.23GB/s 0:01:30", wantPct: 50, wantSpeedBps: 1_230_000_000, wantEtaSeconds: 1*60 + 30, }, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { p := parseProgressFields(tc.line) if p == nil { t.Fatalf("parseProgressFields(%q) returned nil, want non-nil", tc.line) } if p.Pct != tc.wantPct { t.Errorf("pct = %d, want %d", p.Pct, tc.wantPct) } if p.SpeedBps != tc.wantSpeedBps { t.Errorf("speedBps = %d, want %d", p.SpeedBps, tc.wantSpeedBps) } if p.EtaSeconds != tc.wantEtaSeconds { t.Errorf("etaSeconds = %d, want %d", p.EtaSeconds, tc.wantEtaSeconds) } if tc.wantXfrTotal > 0 && p.XfrDone != tc.wantXfrDone { t.Errorf("xfrDone = %d, want %d", p.XfrDone, tc.wantXfrDone) } if tc.wantXfrTotal > 0 && p.XfrTotal != tc.wantXfrTotal { t.Errorf("xfrTotal = %d, want %d", p.XfrTotal, tc.wantXfrTotal) } }) } } func TestIsFileNameLine(t *testing.T) { cases := []struct { name string line string expect bool }{ {"directory path", "Dragon Ball Sleeping Princess in Devil's Castle (1987)/", true}, {"file path", "Dragon Ball Sleeping Princess in Devil's Castle (1987)/Dragon Ball...WEBDL-2160p.mkv", true}, {"sending incremental file list header", "sending incremental file list", false}, {"sent stats", "sent 12,345 bytes received 1,234 bytes", false}, {"total size stats", "total size is 999,999,999", false}, {"Number of files", "Number of files: 10", false}, {"progress line", " 2,260,893,696 7% 51.14MB/s 0:08:45", false}, {"empty", "", false}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got := isFileNameLine(tc.line) if got != tc.expect { t.Errorf("isFileNameLine(%q) = %v, want %v", tc.line, got, tc.expect) } }) } }