1
0
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:
Jesse Li
2019-12-31 12:18:18 -05:00
parent a5e2137e37
commit acd4fe9c62
4 changed files with 28177 additions and 0 deletions

1
go.sum
View File

@@ -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=

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -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