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) }