diff --git a/.gitignore b/.gitignore index 561e7752..d48e6273 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,8 @@ debug .idea/ -bin/ \ No newline at end of file +bin/ + +.torrent.db +.torrent.db-shm +.torrent.db-wal \ No newline at end of file diff --git a/internal/protocol/bt/fetcher_test.go b/internal/protocol/bt/fetcher_test.go index a9fc1bde..290f203e 100644 --- a/internal/protocol/bt/fetcher_test.go +++ b/internal/protocol/bt/fetcher_test.go @@ -1,51 +1,36 @@ package bt import ( - "fmt" "github.com/monkeyWie/gopeed-core/internal/controller" "github.com/monkeyWie/gopeed-core/internal/fetcher" "github.com/monkeyWie/gopeed-core/pkg/base" + "reflect" "testing" ) -func TestFetcher_Resolve_Magnet(t *testing.T) { - fetcher := buildFetcher() - res, err := fetcher.Resolve(&base.Request{ - URL: "magnet:?xt=urn:btih:A213E40628B27B58E70F0DADAC5350CA05403AC4&dn=Microsoft%20Office%20PRO%20Plus%202021%20Retail%20Version%202108%20Build%2014326.2&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce", - }) - if err != nil { - panic(err) - } - fmt.Println(res) -} - func TestFetcher_Resolve_Torrent(t *testing.T) { fetcher := buildFetcher() res, err := fetcher.Resolve(&base.Request{ - URL: "d:/test/test.torrent", + URL: "./testdata/ubuntu-22.04-live-server-amd64.iso.torrent", }) if err != nil { panic(err) } - fmt.Println(res) -} -func TestFetcher_Create(t *testing.T) { - fetcher := buildFetcher() - res, err := fetcher.Resolve(&base.Request{ - URL: "magnet:?xt=urn:btih:A213E40628B27B58E70F0DADAC5350CA05403AC4&dn=Microsoft%20Office%20PRO%20Plus%202021%20Retail%20Version%202108%20Build%2014326.2&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2710%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2780%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337&tr=http%3A%2F%2Fp4p.arenabg.com%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce", - }) - if err != nil { - panic(err) + want := &base.Resource{ + Req: res.Req, + Length: 1466714112, + Range: true, + Files: []*base.FileInfo{ + { + Name: "ubuntu-22.04-live-server-amd64.iso", + Path: ".", + Size: 1466714112, + }, + }, } - if err := fetcher.Create(res, &base.Options{}); err != nil { - panic(err) - } - if err := fetcher.Start(); err != nil { - panic(err) - } - if err := fetcher.Wait(); err != nil { - panic(err) + if !reflect.DeepEqual(want, res) { + t.Errorf("Resolve error = %v, want %v", res, want) } } diff --git a/internal/protocol/bt/testdata/ubuntu-22.04-live-server-amd64.iso.torrent b/internal/protocol/bt/testdata/ubuntu-22.04-live-server-amd64.iso.torrent new file mode 100644 index 00000000..3e323e7c Binary files /dev/null and b/internal/protocol/bt/testdata/ubuntu-22.04-live-server-amd64.iso.torrent differ