summaryrefslogtreecommitdiffstats
path: root/marshall_test.go
blob: ad4d6fd855aa997a2445d407cd0c7ee38b4fc0b9 (plain)
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
package main

import (
	"encoding/json"
	"encoding/xml"
	"fmt"
	"os"
	"testing"
)

func TestMarshallXML(t *testing.T) {
	s := []Scrobble{
		Scrobble{Artist: Correctable{Name: "Led Zeppelin"},
			TrackName: Correctable{Name: "Loser"},
			Time:      1479682785,
			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:      1479682537,
			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)
}