-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathplaylist_test.go
137 lines (98 loc) · 2.37 KB
/
playlist_test.go
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"os"
"path"
"path/filepath"
"testing"
"github.com/issadarkthing/gomu/player"
"github.com/rivo/tview"
)
// Prepares for test
func prepareTest() *Gomu {
gomu := newGomu()
gomu.player = player.New(0)
gomu.queue = newQueue()
gomu.playlist = &Playlist{
TreeView: tview.NewTreeView(),
}
gomu.app = tview.NewApplication()
err := execConfig(expandFilePath(testConfigPath))
if err != nil {
panic(err)
}
gomu.colors = newColor()
rootDir, err := filepath.Abs("./test")
if err != nil {
panic(err)
}
root := tview.NewTreeNode("music")
rootAudioFile := new(player.AudioFile)
rootAudioFile.SetName(root.GetText())
rootAudioFile.SetPath(rootDir)
root.SetReference(rootAudioFile)
populate(root, rootDir, false)
gomu.playlist.SetRoot(root)
return gomu
}
func TestPopulate(t *testing.T) {
gomu = newGomu()
err := execConfig(expandFilePath(testConfigPath))
if err != nil {
t.Error(err)
}
gomu.colors = newColor()
rootDir, err := filepath.Abs("./test")
if err != nil {
panic(err)
}
expected := 0
walkFn := func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
expected++
return nil
}
f, e := os.Open(path)
if e != nil {
return e
}
defer f.Close()
expected++
return nil
}
// calculate the amount of mp3 files and directories
filepath.Walk(rootDir, walkFn)
root := tview.NewTreeNode(path.Base(rootDir))
rootAudioFile := new(player.AudioFile)
rootAudioFile.SetName("Music")
rootAudioFile.SetIsAudioFile(false)
populate(root, rootDir, false)
gotItems := 0
root.Walk(func(node, _ *tview.TreeNode) bool {
gotItems++
return true
})
// ignore config, config.test and arbitrary_file.txt
gotItems += 3
if gotItems != expected {
t.Errorf("Invalid amount of file; expected %d got %d", expected, gotItems)
}
}
func TestAddAllToQueue(t *testing.T) {
gomu = prepareTest()
var songs []*tview.TreeNode
gomu.playlist.GetRoot().Walk(func(node, parent *tview.TreeNode) bool {
if node.GetReference().(*player.AudioFile).Name() == "rap" {
gomu.playlist.addAllToQueue(node)
}
return true
})
queue := gomu.queue.getItems()
for i, song := range songs {
audioFile := song.GetReference().(*player.AudioFile)
// strips the path of the song in the queue
s := filepath.Base(queue[i])
if audioFile.Name() != s {
t.Errorf("Expected \"%s\", got \"%s\"", audioFile.Name(), s)
}
}
}