-
Notifications
You must be signed in to change notification settings - Fork 0
/
query_test.go
111 lines (99 loc) · 3.17 KB
/
query_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
package cdb
import (
"fmt"
"path/filepath"
"testing"
"github.com/spf13/viper"
)
var lib *Lib
var books []Book
func TestNewLib(t *testing.T) {
path := viper.GetString("libraries.audiobooks.path")
p := filepath.Join(path, "audiobooks")
lib = NewLib(
p,
IsAudiobooks(),
//PrintQuery(),
)
}
func booksByID() ([]Book, error) {
q := lib.NewQuery().GetByID(9783) //.Limit(1) //.GetByID(1)
return getBooks(q)
}
func TestQueryByID(t *testing.T) {
books, err := booksByID()
if err != nil {
fmt.Printf("error %v\n", err)
}
if len(books) != 1 {
t.Error("expected one book")
}
}
//func TestSaveMetadata(t *testing.T) {
// books, err := booksByID()
// if err != nil {
// fmt.Printf("error %v\n", err)
// }
// for _, book := range books {
// name := filepath.Join("testdata", "book", casing.Snake(book.Title))
// for _, ext := range []string{".json", ".toml", ".yaml"} {
// //var opt EncoderOpt
// switch ext {
// case ".json":
// //opt = EncodeJSON
// case ".toml":
// //opt = EncodeTOML
// case ".yaml":
// err := book.Encode(EncodeYAML).WriteTo(os.Stdout)
// //err := NewEnc(book, EncodeYAML).WriteTo(os.Stdout)
// if err != nil {
// t.Error(err)
// }
// //opt = EncodeYAML
// }
// println(name)
// //err := book.Save(name + ext)
// //if err != nil {
// // fmt.Printf("error %v\n", err)
// //}
// }
// }
//}
//func TestCalibreFlags(t *testing.T) {
// books, err := booksByID()
// if err != nil {
// fmt.Printf("error %v\n", err)
// }
// for _, book := range books {
// flags := book.CalibredbFlags()
// }
//}
func getBooks(q *Query) ([]Book, error) {
r, err := lib.GetBooks(q)
if err != nil {
fmt.Printf("error %v\n", err)
}
//books, err := r.Books()
//if err != nil {
// fmt.Printf("error %v\n", err)
//}
//for _, b := range books {
// fmt.Printf("%#v\n", b)
//}
return r.Books()
}
var flags = []string{
"authors:Charles Dean & R.A. Mejia",
"publisher:Single Player Books",
"#narrators:Daniel Wisniewski & Elizabeth Plant",
"series_index:2",
"#duration:12:23:00",
"languages:eng",
"series:Upgrade Apocalypse",
"tags:litrpg",
"title:The Upgrade Apocalypse: Book 2",
"author_sort:Charles Dean & R.A. Mejia",
"pubdate:0101-01-01",
"sort:Upgrade Apocalypse: Book 2, The",
"comments:<p>Welcome to the end of the world, where the lines between reality and a fantasy game blur. The survivors must not only face the relentless hordes of the Hell-Cursed, but also the cruel fate of death itself. </p> <p>Join Chedderfield and his companions as they navigate a post-apocalyptic wasteland filled with dark humor, horror, and heart-wrenching deaths. Get ready for twists, turns, and gut-wrenching losses as you follow the journey to uncover the truth behind Archimedes' death and the true meaning of survival in a world where anything can happen.</p> <p>Welcome to hell on Earth. Welcome to <i>The Upgrade Apocalypse!</i></p> <p>Warning: This book contains apocalyptic adventures, creative cursing, jokes about the apocalypse, an interesting card skill system, horror monsters to fight or flee from, and character deaths when they fail their save throws.</p>",
}