|
@@ -11,6 +11,7 @@ import (
|
|
|
|
|
|
var parseTemplate *template.Template
|
|
var parseTemplate *template.Template
|
|
var readfileError, templateError, createError, mkdirallError, parseError, walkError error
|
|
var readfileError, templateError, createError, mkdirallError, parseError, walkError error
|
|
|
|
+var mockOperation = func(b []byte) []byte { return b }
|
|
|
|
|
|
func init() {
|
|
func init() {
|
|
readfile = func(_ string) ([]byte, error) { return nil, readfileError }
|
|
readfile = func(_ string) ([]byte, error) { return nil, readfileError }
|
|
@@ -94,43 +95,43 @@ func TestMulti(t *testing.T) {
|
|
statError = nil
|
|
statError = nil
|
|
|
|
|
|
// no pages
|
|
// no pages
|
|
- if e := g.multi(); e != nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e != nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test full pass
|
|
// test full pass
|
|
- if e := g.multi(); e != nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e != nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test full pass relative
|
|
// test full pass relative
|
|
g.Relative = true
|
|
g.Relative = true
|
|
- if e := g.multi(); e != nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e != nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test failing execute
|
|
// test failing execute
|
|
templateError = mockError
|
|
templateError = mockError
|
|
- if e := g.multi(); e == nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test failing file creation
|
|
// test failing file creation
|
|
createError = mockError
|
|
createError = mockError
|
|
- if e := g.multi(); e == nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test failing to read the file
|
|
// test failing to read the file
|
|
readfileError = mockError
|
|
readfileError = mockError
|
|
- if e := g.multi(); e == nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test dir creation failure
|
|
// test dir creation failure
|
|
mkdirallError = mockError
|
|
mkdirallError = mockError
|
|
statError = mockError
|
|
statError = mockError
|
|
- if e := g.multi(); e == nil {
|
|
|
|
|
|
+ if e := g.multi(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -145,32 +146,32 @@ func TestSingle(t *testing.T) {
|
|
templateError = nil
|
|
templateError = nil
|
|
|
|
|
|
// test full pass
|
|
// test full pass
|
|
- if e := g.single(); e != nil {
|
|
|
|
|
|
+ if e := g.single(mockOperation); e != nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test failing execute
|
|
// test failing execute
|
|
templateError = mockError
|
|
templateError = mockError
|
|
- if e := g.single(); e == nil {
|
|
|
|
|
|
+ if e := g.single(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test create error
|
|
// test create error
|
|
createError = mockError
|
|
createError = mockError
|
|
- if e := g.single(); e == nil {
|
|
|
|
|
|
+ if e := g.single(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test fail mkdirall
|
|
// test fail mkdirall
|
|
mkdirallError = mockError
|
|
mkdirallError = mockError
|
|
statError = mockError
|
|
statError = mockError
|
|
- if e := g.single(); e == nil {
|
|
|
|
|
|
+ if e := g.single(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test fail readfile
|
|
// test fail readfile
|
|
readfileError = mockError
|
|
readfileError = mockError
|
|
- if e := g.single(); e == nil {
|
|
|
|
|
|
+ if e := g.single(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -182,25 +183,25 @@ func TestGenerate(t *testing.T) {
|
|
parseTemplate = template.New("test")
|
|
parseTemplate = template.New("test")
|
|
|
|
|
|
// test full pass
|
|
// test full pass
|
|
- if e := g.Generate(); e != nil {
|
|
|
|
|
|
+ if e := g.Generate(mockOperation); e != nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test book mode full pass
|
|
// test book mode full pass
|
|
g.Book = true
|
|
g.Book = true
|
|
- if e := g.Generate(); e == nil {
|
|
|
|
|
|
+ if e := g.Generate(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test walk error
|
|
// test walk error
|
|
walkError = mockError
|
|
walkError = mockError
|
|
- if e := g.Generate(); e == nil {
|
|
|
|
|
|
+ if e := g.Generate(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
|
|
|
|
// test template error
|
|
// test template error
|
|
parseError = mockError
|
|
parseError = mockError
|
|
- if e := g.Generate(); e == nil {
|
|
|
|
|
|
+ if e := g.Generate(mockOperation); e == nil {
|
|
t.FailNow()
|
|
t.FailNow()
|
|
}
|
|
}
|
|
}
|
|
}
|