1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
"os"
"testing"
"time"
)
func TestMarshallXML(t *testing.T) {
s := []Scrobble{
Scrobble{Artist: Correctable{Name: "Led Zeppelin"},
TrackName: Correctable{Name: "Loser"},
Time: time.Unix(1479682785, 0),
Album: Correctable{Name: "Mellow Gold"}},
}
scrobbles := Scrobbles{Scrobbles: s,
Attrs: Attrs{1, 0}}
response := LFMResponse{Status: "ok",
Response: scrobbles}
output, err := xml.MarshalIndent(response, " ", " ")
if err != nil {
fmt.Printf("error: %v\n", err)
}
fmt.Printf(xml.Header)
os.Stdout.Write(output)
}
func TestMarshallJSON(t *testing.T) {
s := []Scrobble{
Scrobble{Artist: Correctable{Name: "Mumford & Sons"},
Time: time.Unix(1479682537, 0),
Album: Correctable{Name: "Sign No More"},
TrackName: Correctable{Name: "Little Lion Man"}},
}
scrobbles := Scrobbles{Scrobbles: s,
Attrs: Attrs{1, 0}}
response := LFMResponse{Status: "ok",
Response: scrobbles}
output, err := json.MarshalIndent(response, " ", " ")
if err != nil {
fmt.Printf("error: %v\n", err)
}
os.Stdout.Write(output)
}
|