mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-25 11:03:56 +00:00
* Add game library * Add missing local game lib files * Add missing return statement * Use v2 suffix * Bump the dependencies
46 lines
897 B
Go
46 lines
897 B
Go
package games
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestLibraryScan(t *testing.T) {
|
|
tests := []struct {
|
|
directory string
|
|
expected []string
|
|
}{
|
|
{
|
|
directory: "../../assets/games",
|
|
expected: []string{
|
|
"Super Mario Bros", "Sushi The Cat", "anguna",
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
library := NewLibrary(Config{
|
|
BasePath: test.directory,
|
|
Supported: []string{"gba", "zip", "nes"},
|
|
Ignored: []string{"neogeo", "pgm"},
|
|
})
|
|
library.Scan()
|
|
games := library.GetAll()
|
|
|
|
list := _map(games, func(meta GameMetadata) string {
|
|
return meta.Name
|
|
})
|
|
|
|
if !reflect.DeepEqual(test.expected, list) {
|
|
t.Errorf("Test fail for dir %v with %v != %v", test.directory, list, test.expected)
|
|
}
|
|
}
|
|
}
|
|
|
|
func _map(vs []GameMetadata, f func(info GameMetadata) string) []string {
|
|
vsm := make([]string, len(vs))
|
|
for i, v := range vs {
|
|
vsm[i] = f(v)
|
|
}
|
|
return vsm
|
|
}
|