-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add small improvements and setup test for pkg/xspf
- add server header to http router - simplify playlist struct - add test for pkg/xspf - improve logging and error handling in cmd/xplay
- Loading branch information
1 parent
da25012
commit 35b57a4
Showing
7 changed files
with
87 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package xspf | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"strconv" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
const testXml = ` | ||
<playlist version="1" xmlns="http://xspf.org/ns/0/"> | ||
<title>Playlist</title> | ||
<date>2005-01-08T17:10:47-05:00</date> | ||
<trackList> | ||
<track> | ||
<location>1.mp3</location> | ||
<title>1</title> | ||
</track> | ||
<track> | ||
<location>2.mp3</location> | ||
<title>2</title> | ||
</track> | ||
</trackList> | ||
</playlist> | ||
` | ||
|
||
func newTestPlaylist() *PlayList { | ||
list := &PlayList{ | ||
Title: "Playlist", | ||
Date: "2005-01-08T17:10:47-05:00", | ||
} | ||
for i := 1; i < 3; i++ { | ||
list.Tracks = append(list.Tracks, &Track{ | ||
Location: strconv.Itoa(i) + ".mp3", Title: strconv.Itoa(i), ImageExt: "jpg", | ||
}) | ||
} | ||
return list | ||
} | ||
|
||
func TestEncodeXspf(t *testing.T) { | ||
buf := bytes.NewBuffer([]byte{}) | ||
if err := EncodeXspf(buf, newTestPlaylist()); err != nil { | ||
t.Fatal(err) | ||
} | ||
if strings.Trim(buf.String(), "\n") != strings.Trim(testXml, "\n") { | ||
t.Errorf("Encoded playlist does not match expected:\n%s", buf.String()) | ||
} | ||
} | ||
|
||
func TestGenerate(t *testing.T) { | ||
if err := Generate(io.Discard, newTestPlaylist()); err != nil { | ||
t.Error(err) | ||
} | ||
} | ||
|
||
func TestBufferedGenerate(t *testing.T) { | ||
if _, err := BufferedGenerate(newTestPlaylist()); err != nil { | ||
t.Error(err) | ||
} | ||
} |