TestStartDownload_EnforcesAbsolutePath verifies that startDownload forces the path to be absolute.
(t *testing.T)
| 13 | |
| 14 | // TestStartDownload_EnforcesAbsolutePath verifies that startDownload forces the path to be absolute. |
| 15 | func TestStartDownload_EnforcesAbsolutePath(t *testing.T) { |
| 16 | // wd, _ := os.Getwd() |
| 17 | tmpDir, _ := os.MkdirTemp("", "surge-test") |
| 18 | defer func() { _ = os.RemoveAll(tmpDir) }() |
| 19 | |
| 20 | ch := make(chan any, 10) |
| 21 | pool := download.NewWorkerPool(ch, 1) |
| 22 | |
| 23 | m := RootModel{ |
| 24 | Settings: config.DefaultSettings(), |
| 25 | Service: core.NewLocalDownloadServiceWithInput(pool, ch), |
| 26 | downloads: []*DownloadModel{}, |
| 27 | list: NewDownloadList(80, 20), // Initialize list |
| 28 | } |
| 29 | |
| 30 | // Test case 1: Relative path |
| 31 | relPath := "subdir" |
| 32 | url := "http://example.com/file.zip" |
| 33 | |
| 34 | m, _ = m.startDownload(url, nil, nil, relPath, false, "file.zip", "test-id-1") |
| 35 | |
| 36 | // We expect the new download to be appended |
| 37 | if len(m.downloads) != 1 { |
| 38 | t.Fatalf("Expected 1 download, got %d", len(m.downloads)) |
| 39 | } |
| 40 | |
| 41 | dm := m.downloads[0] |
| 42 | // Verify Destination is absolute (if we updated the code to set it) |
| 43 | // Currently the code DOES NOT set dm.Destination in startDownload. |
| 44 | // We should update the code to set it for better UX and testability. |
| 45 | |
| 46 | // If the code is updated, this assertion should pass: |
| 47 | expected := filepath.Join(utils.EnsureAbsPath(relPath), "file.zip") |
| 48 | if dm.Destination != expected { |
| 49 | t.Errorf("Destination not absolute. Got %q, want %q", dm.Destination, expected) |
| 50 | } |
| 51 | } |
nothing calls this directly
no test coverage detected