aboutsummaryrefslogtreecommitdiffstats
path: root/marshall_test.go
blob: a916556b32b452564de1dc02cdaef060ec58592a (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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 TestMarshallXMLToken(t *testing.T) {
	token := Token{Val: randomToken(16)}
	response := LFMResponse{Status: "ok",
		Response: token}
	output, err := xml.MarshalIndent(response, "  ", "    ")
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}
	fmt.Printf(xml.Header)
	os.Stdout.Write(output)
}

func TestMarshallJSONToken(t *testing.T) {
	token := Token{Val: randomToken(16)}
	output, err := json.MarshalIndent(token, "  ", "    ")
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}
	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}}
	output, err := json.MarshalIndent(scrobbles, "  ", "    ")
	if err != nil {
		fmt.Printf("error: %v\n", err)
	}
	os.Stdout.Write(output)
}