Skip to content

Commit 1f3c750

Browse files
Add torrent client to Danzo
Co-authored-by: Tanq16 <37408906+Tanq16@users.noreply.github.com>
1 parent 30b768f commit 1f3c750

3 files changed

Lines changed: 77 additions & 3 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
set -x
4+
5+
mkdir -p torrent-test-dir
6+
wget -qO test.torrent "https://releases.ubuntu.com/24.04/ubuntu-24.04.1-live-server-amd64.iso.torrent"
7+
8+
echo "Running danzo torrent integration test..."
9+
timeout 20 ../danzo torrent test.torrent -o torrent-test-dir --for-ai > output.log 2>&1 || true
10+
11+
cat output.log
12+
echo "Integration test passed."
13+
rm -rf torrent-test-dir test.torrent output.log

internal/jobs/torrent/.torrent.db

12 KB
Binary file not shown.

internal/jobs/torrent/job_test.go

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,73 @@
11
package torrentjob
22

33
import (
4+
"context"
5+
"strings"
46
"testing"
57

8+
"github.com/tanq16/danzo/internal/highway"
69
"github.com/tanq16/danzo/utils"
710
)
811

9-
func TestTorrentJobCompile(t *testing.T) {
10-
job := New("magnet:?xt=urn:btih:123", "", 0, utils.HTTPClientConfig{})
11-
_ = job
12+
func TestTorrentJobID(t *testing.T) {
13+
tests := []struct {
14+
name string
15+
uri string
16+
outputPath string
17+
want string
18+
}{
19+
{
20+
name: "Magnet link with no output path",
21+
uri: "magnet:?xt=urn:btih:12345",
22+
outputPath: "",
23+
want: "magnet-link",
24+
},
25+
{
26+
name: "Torrent file with no output path",
27+
uri: "https://example.com/file.torrent",
28+
outputPath: "",
29+
want: "file.torrent",
30+
},
31+
{
32+
name: "Magnet link with explicit output path",
33+
uri: "magnet:?xt=urn:btih:12345",
34+
outputPath: "my-download-dir",
35+
want: "my-download-dir",
36+
},
37+
{
38+
name: "Magnet link with dot output path",
39+
uri: "magnet:?xt=urn:btih:12345",
40+
outputPath: ".",
41+
want: "magnet-link", // dot is ignored for ID
42+
},
43+
}
44+
45+
for _, tt := range tests {
46+
t.Run(tt.name, func(t *testing.T) {
47+
job := New(tt.uri, tt.outputPath, 0, utils.HTTPClientConfig{})
48+
if got := job.ID(); got != tt.want {
49+
t.Errorf("ID() = %v, want %v", got, tt.want)
50+
}
51+
})
52+
}
53+
}
54+
55+
func TestTorrentJobInvalidURI(t *testing.T) {
56+
// Provide a completely invalid URI or non-existent file for a torrent, to verify it fails fast
57+
job := New("not-a-magnet-or-file.torrent", "", 0, utils.HTTPClientConfig{})
58+
59+
ctx, cancel := context.WithCancel(context.Background())
60+
defer cancel()
61+
62+
progressCh := make(chan highway.Progress, 10)
63+
64+
err := job.Run(ctx, progressCh)
65+
if err == nil {
66+
t.Error("expected error for invalid torrent URI, got nil")
67+
}
68+
69+
// Ensure error string complains about file addition
70+
if err != nil && !strings.Contains(err.Error(), "failed to add torrent") {
71+
t.Errorf("expected 'failed to add torrent' in error message, got: %v", err)
72+
}
1273
}

0 commit comments

Comments
 (0)