You've already forked torrent-client
mirror of
https://github.com/veggiedefender/torrent-client.git
synced 2025-11-06 09:29:16 +02:00
Implement golden file test for torrentfile.Open
This commit is contained in:
1
go.sum
1
go.sum
@@ -4,6 +4,7 @@ github.com/jackpal/bencode-go v0.0.0-20180813173944-227668e840fa h1:ym9I4Q1lJG8n
|
|||||||
github.com/jackpal/bencode-go v0.0.0-20180813173944-227668e840fa/go.mod h1:5FSBQ74yhCl5oQ+QxRPYzWMONFnxbL68/23eezsBI5c=
|
github.com/jackpal/bencode-go v0.0.0-20180813173944-227668e840fa/go.mod h1:5FSBQ74yhCl5oQ+QxRPYzWMONFnxbL68/23eezsBI5c=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
|||||||
BIN
torrentfile/testdata/archlinux-2019.12.01-x86_64.iso.torrent
vendored
Normal file
BIN
torrentfile/testdata/archlinux-2019.12.01-x86_64.iso.torrent
vendored
Normal file
Binary file not shown.
28146
torrentfile/testdata/archlinux-2019.12.01-x86_64.iso.torrent.golden.json
vendored
Normal file
28146
torrentfile/testdata/archlinux-2019.12.01-x86_64.iso.torrent.golden.json
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -1,11 +1,41 @@
|
|||||||
package torrentfile
|
package torrentfile
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var update = flag.Bool("update", false, "update .golden.json files")
|
||||||
|
|
||||||
|
func TestOpen(t *testing.T) {
|
||||||
|
input, err := os.Open("testdata/archlinux-2019.12.01-x86_64.iso.torrent")
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
torrent, err := Open(input)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
goldenPath := "testdata/archlinux-2019.12.01-x86_64.iso.torrent.golden.json"
|
||||||
|
if *update {
|
||||||
|
serialized, err := json.MarshalIndent(torrent, "", " ")
|
||||||
|
require.Nil(t, err)
|
||||||
|
ioutil.WriteFile(goldenPath, serialized, 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := &TorrentFile{}
|
||||||
|
golden, err := ioutil.ReadFile(goldenPath)
|
||||||
|
require.Nil(t, err)
|
||||||
|
err = json.Unmarshal(golden, expected)
|
||||||
|
require.Nil(t, err)
|
||||||
|
|
||||||
|
assert.Equal(t, expected, torrent)
|
||||||
|
}
|
||||||
|
|
||||||
func TestToTorrent(t *testing.T) {
|
func TestToTorrent(t *testing.T) {
|
||||||
tests := map[string]struct {
|
tests := map[string]struct {
|
||||||
input *bencodeTorrent
|
input *bencodeTorrent
|
||||||
|
|||||||
Reference in New Issue
Block a user