-
Notifications
You must be signed in to change notification settings - Fork 17
/
ebookdl_test.go
152 lines (136 loc) · 4.01 KB
/
ebookdl_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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package ebookdownloader
import (
"os"
"testing"
. "gopkg.in/check.v1"
)
var testbi = BookInfo{
Name: "我是谁",
Author: "sndnvaps",
Description: "这是我随便写的测试内容简介!",
Volumes: V, //分卷信息
Chapters: Chapters,
DlCoverFromWeb: false, //使用直接生成的封面
}
var V = []Volume{
{
PrevChapterID: 0,
CurrentVolume: "第一卷", //插入位置,第一章前面
NextChapterID: 2,
},
{
PrevChapterID: 2,
CurrentVolume: "第二卷", //插入位置,第三章前面
NextChapterID: 3,
},
{
PrevChapterID: 5,
CurrentVolume: "第三卷", //插入位置,第六章前面
NextChapterID: 6,
},
}
var Chapters = []Chapter{
{
Title: "第一章",
Content: "这是第一章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第二章",
Content: "这是第二章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第三章",
Content: "这是第三章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第四章",
Content: "这是第四章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第五章",
Content: "这是第五章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第六章",
Content: "这是第六章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第七章",
Content: "这是第七章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第八章",
Content: "这是第八章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第九章",
Content: "这是第九章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
{
Title: "第十章",
Content: "这是第十章\r\n内容测试\r\n",
Link: "https://github.com/sndnvaps/ebookdownloader",
},
}
var savePath = "./outputs/" + testbi.Name + "-" + testbi.Author
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
func (s *MySuite) TestBookInfo(c *C) {
bookname := "我是谁"
c.Assert(bookname, Equals, testbi.Name)
author := "sndnvaps"
c.Assert(author, Equals, testbi.Author)
size := len(testbi.Chapters)
c.Assert(size, Equals, 10)
link := "https://github.com/sndnvaps/ebookdownloader"
c.Assert(link, Equals, testbi.Chapters[0].Link)
}
func (s *MySuite) TestGenerateTxt(c *C) {
testbi.ChangeVolumeState(true /* hasVolume */)
testbi.GenerateTxt()
savename := savePath + "/" + testbi.Name + "-" + testbi.Author + ".txt"
c.Assert(isExist(savename), Equals, true)
os.RemoveAll(savePath)
}
func (s *MySuite) TestGenerateMobi(c *C) {
testbi.ChangeVolumeState(true /* hasVolume */)
testbi.SetKindleEbookType(true /* isMobi */, false /* isAwz3 */)
testbi.GenerateISBN() //先生成ISBN码
testbi.GenerateMobi()
savename := savePath + "/" + testbi.Name + "-" + testbi.Author + ".mobi"
c.Assert(isExist(savename), Equals, true)
//os.RemoveAll(savePath)
}
func (s *MySuite) TestGenerateAzw3(c *C) {
testbi.ChangeVolumeState(true /* hasVolume */)
testbi.SetKindleEbookType(false /* isMobi */, true /* isAzw3 */)
testbi.GenerateISBN() //先生成ISBN码
testbi.GenerateMobi()
savename := savePath + "/" + testbi.Name + "-" + testbi.Author + ".azw3"
c.Assert(isExist(savename), Equals, true)
os.RemoveAll(savePath)
}
func (s *MySuite) TestGenerateEPUB(c *C) {
testbi.GenerateISBN() //先生成ISBN码
testbi.GenerateEPUB()
savename := savePath + "/" + testbi.Name + "-" + testbi.Author + ".epub"
c.Assert(isExist(savename), Equals, true)
os.RemoveAll(savePath)
}
// IsExist checks whether a file or directory exists.
// It returns false when the file or directory does not exist.
func isExist(path string) bool {
_, err := os.Stat(path)
return err == nil || os.IsExist(err)
}