8 func load_file(name string, t *testing.T) []byte {
9 data, err := ioutil.ReadFile(name)
16 func TestBothInterface(t *testing.T) {
17 data1 := load_file("_testdata/archlinux-2011.08.19-netinstall-i686.iso.torrent", t)
20 err := Unmarshal(data1, &iface)
25 data2, err := Marshal(iface)
30 if !bytes.Equal(data1, data2) {
31 t.Fatalf("equality expected\n")
35 type torrent_file struct {
37 Name string `bencode:"name"`
38 Length int64 `bencode:"length"`
39 MD5Sum string `bencode:"md5sum,omitempty"`
40 PieceLength int64 `bencode:"piece length"`
41 Pieces string `bencode:"pieces"`
42 Private bool `bencode:"private,omitempty"`
45 Announce string `bencode:"announce"`
46 AnnounceList [][]string `bencode:"announce-list,omitempty"`
47 CreationDate int64 `bencode:"creation date,omitempty"`
48 Comment string `bencode:"comment,omitempty"`
49 CreatedBy string `bencode:"created by,omitempty"`
50 URLList interface{} `bencode:"url-list,omitempty"`
53 func TestBoth(t *testing.T) {
54 data1 := load_file("_testdata/archlinux-2011.08.19-netinstall-i686.iso.torrent", t)
57 err := Unmarshal(data1, &f)
62 t.Logf("Name: %s\n", f.Info.Name)
63 t.Logf("Length: %v bytes\n", f.Info.Length)
64 t.Logf("Announce: %s\n", f.Announce)
65 t.Logf("CreationDate: %s\n", time.Unix(f.CreationDate, 0).String())
66 t.Logf("CreatedBy: %s\n", f.CreatedBy)
67 t.Logf("Comment: %s\n", f.Comment)
69 data2, err := Marshal(&f)
74 if !bytes.Equal(data1, data2) {
75 t.Fatalf("equality expected")