/
cmd_load_test.go
82 lines (70 loc) · 1.78 KB
/
cmd_load_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
package main
// The testing is pretty pathetic at the moment, but at least there's
// something to build on.
//
// While there's only one test at the moment, it's actually testing a fair
// amount (not exactly an exemplary unit test):
import (
"io"
"log"
"strings"
"testing"
"github.com/BurntSushi/csql"
"github.com/BurntSushi/goim/imdb"
)
var (
testDB *imdb.DB
testDriver, testDsn = "sqlite3", "/tmp/goim-test.sqlite"
)
var (
testLists = mapFetcher{
"movies": `
MOVIES LIST
===========
The Matrix (1999) 1999
The Matrix Reloaded (2003) 2003
The Matrix Revolutions (2003) 2003
V for Vendetta (2005) 2005
"The Simpsons" (1989) 1989-????
"The Simpsons" (1989) {Lisa the Iconoclast (#7.16)} 1996
"The Simpsons" (1989) {HOMR (#12.9)} 2001
`,
}
)
type mapFetcher map[string]string
type readCloser struct {
io.Reader
}
func (rc readCloser) Close() error {
return nil
}
func (mf mapFetcher) list(name string) (io.ReadCloser, error) {
return readCloser{strings.NewReader(mf[name])}, nil
}
func init() {
var err error
testDB, err = imdb.Open(testDriver, testDsn)
if err != nil {
log.Fatal(err)
}
}
func TestLoadMovies(t *testing.T) {
var exp = map[string]int{
"movies": 4, "tvs": 1, "episodes": 2,
}
if err := loadMovies(testDriver, testDsn, testLists); err != nil {
t.Fatal(err)
}
movies := csql.Count(testDB, "SELECT COUNT(*) FROM movie")
tvs := csql.Count(testDB, "SELECT COUNT(*) FROM tvshow")
episodes := csql.Count(testDB, "SELECT COUNT(*) FROM episode")
if movies != exp["movies"] {
t.Fatalf("Expected %d movies but got %d", exp["movies"], movies)
}
if tvs != exp["tvs"] {
t.Fatalf("Expected %d tvs but got %d", exp["tvs"], tvs)
}
if episodes != exp["episodes"] {
t.Fatalf("Expected %d episodes but got %d", exp["episodes"], episodes)
}
}