This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmangarock_test.go
78 lines (70 loc) · 1.68 KB
/
mangarock_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
package mangarock_test
import (
"testing"
"github.com/bake/httpcache"
"github.com/bake/httpcache/diskcache"
"github.com/bake/mangarock"
)
var c *mangarock.Client
func init() {
client := httpcache.New(diskcache.New("testdeta", diskcache.NoExpiration)).Client()
c = mangarock.New(mangarock.WithHTTPClient(client))
}
func TestLatest(t *testing.T) {
mangas, err := c.Latest(0)
if err != nil {
t.Fatal(err)
}
if len(mangas) == 0 {
t.Fatal("no mangas returned")
}
if mangas[0].Author.ID == "" {
t.Fatal("author id empty")
}
}
func TestManga(t *testing.T) {
id := "mrs-serie-100177863"
name := "Fushigi Neko no Kyuu-chan"
manga, err := c.Manga(id)
if err != nil {
t.Fatal(err)
}
if manga.Name != name {
t.Fatalf("expected name to be %s, got %s", name, manga.Name)
}
}
func TestSearch(t *testing.T) {
query := "kyuu-chan"
num := 1
name := "Fushigi Neko no Kyuu-chan"
author := "Nitori Sasami"
mangas, err := c.Search(query)
if err != nil {
t.Fatal(err)
}
if len(mangas) != num {
t.Fatalf("expected %d results, got %d", num, len(mangas))
}
if mangas[0].Name != name {
t.Fatalf("expected name to be %s, got %s", name, mangas[0].Name)
}
if mangas[0].Author.Name != author {
t.Fatalf("expected author to be %s, got %s", author, mangas[0].Author.Name)
}
}
func TestChapter(t *testing.T) {
mid := "mrs-serie-100177863"
cid := "mrs-chapter-100177864"
name := "Chapter 1: Snow"
pages := 1
chapter, err := c.Chapter(mid, cid)
if err != nil {
t.Fatal(err)
}
if chapter.Name != name {
t.Fatalf("expected name to be %s, got %s", name, chapter.Name)
}
if len(chapter.Pages) != pages {
t.Fatalf("expected number of pages to be %d, got %d", pages, len(chapter.Pages))
}
}