55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
//go:build linux || freebsd
|
|
// +build linux freebsd
|
|
|
|
package sftp
|
|
|
|
import (
|
|
"net/url"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"codeberg.org/petrbalvin/goget/internal/core"
|
|
"codeberg.org/petrbalvin/goget/internal/output"
|
|
)
|
|
|
|
// TestSaveSFTPResume verifies the partial-progress sidecar for the
|
|
// SFTP single-file path. The SFTP parallel workers don't read attr.Size
|
|
// in the download loop, so Total is recorded as 0 (only Downloaded
|
|
// is known reliably). A future enhancement could plumb totalSize
|
|
// through sftpDownloadFile if more accurate accounting is needed.
|
|
func TestSaveSFTPResume(t *testing.T) {
|
|
tmp := t.TempDir()
|
|
out := filepath.Join(tmp, "file.bin")
|
|
|
|
u, err := url.Parse("sftp://user@host:22/file.bin")
|
|
if err != nil {
|
|
t.Fatalf("parse URL: %v", err)
|
|
}
|
|
req := &core.DownloadRequest{
|
|
URL: u,
|
|
Output: out,
|
|
}
|
|
|
|
saveSFTPResume(req, 12345)
|
|
|
|
meta, err := output.LoadResumeMetadata(out)
|
|
if err != nil {
|
|
t.Fatalf("LoadResumeMetadata: %v", err)
|
|
}
|
|
if meta == nil {
|
|
t.Fatal("expected resume metadata, got nil")
|
|
}
|
|
if meta.Downloaded != 12345 {
|
|
t.Errorf("Downloaded = %d, want 12345", meta.Downloaded)
|
|
}
|
|
if meta.URL != "sftp://user@host:22/file.bin" {
|
|
t.Errorf("URL = %q", meta.URL)
|
|
}
|
|
// Total is 0 because the parallel worker doesn't read attr.Size;
|
|
// the resume code path uses this as "size unknown" and works
|
|
// regardless of Total.
|
|
if meta.Total != 0 {
|
|
t.Errorf("Total = %d, want 0 (size unknown for SFTP parallel workers)", meta.Total)
|
|
}
|
|
}
|