grim/resticide
Clone
Summary
Browse
Changes
Graph
Give the --help output some tlc, also added a --version argument
develop
2016-07-09, Gary Kramlich
32bc94f303e2
Give the --help output some tlc, also added a --version argument
package
reporter
import
(
"testing"
rtest
"bitbucket.org/rw_grim/resticide/test"
)
type
MockHandler
struct
{
init
bool
start
bool
finish
bool
testStart
bool
testFinish
bool
loadTestsFailed
bool
loadTestFailed
bool
}
func
(
m
*
MockHandler
)
Init
(
v
bool
)
{
m
.
init
=
true
}
func
(
m
*
MockHandler
)
Start
(
t
int
)
{
m
.
start
=
true
}
func
(
m
*
MockHandler
)
Finish
(
t
int
,
p
int
,
f
int
)
{
m
.
finish
=
true
}
func
(
m
*
MockHandler
)
TestStart
(
t
rtest
.
Test
)
{
m
.
testStart
=
true
}
func
(
m
*
MockHandler
)
TestFinish
(
t
rtest
.
Test
,
r
rtest
.
Result
)
{
m
.
testFinish
=
true
}
func
(
m
*
MockHandler
)
LoadTestsFailed
(
e
error
)
{
m
.
loadTestsFailed
=
true
}
func
(
m
*
MockHandler
)
LoadTestFailed
(
p
string
,
e
error
)
{
m
.
loadTestFailed
=
true
}
func
TestNewReporter
(
t
*
testing
.
T
)
{
vals
:=
[]
bool
{
true
,
false
}
for
_
,
v
:=
range
vals
{
r
:=
NewReporter
(
v
)
if
r
.
verbose
!=
v
{
t
.
Errorf
(
"verbose flag was not honored"
)
}
}
}
func
TestReporterAddHandler
(
t
*
testing
.
T
)
{
r
:=
NewReporter
(
false
)
if
len
(
r
.
handlers
)
!=
0
{
t
.
Errorf
(
"handlers did not default to an empty list"
)
}
h
:=
&
MockHandler
{}
r
.
AddHandler
(
h
)
if
len
(
r
.
handlers
)
!=
1
{
t
.
Errorf
(
"failed to add handler"
)
}
if
h
.
init
!=
true
{
t
.
Errorf
(
"ReportHandler.Init was not called"
)
}
// test Reporter.Start
if
h
.
start
!=
false
{
t
.
Errorf
(
"MockHandler.start was not initialized to false"
)
}
r
.
Start
(
1
)
if
h
.
start
!=
true
{
t
.
Errorf
(
"ReportHandler.Start was not called"
)
}
// test Reporter.Finish
if
h
.
finish
!=
false
{
t
.
Errorf
(
"MockHandler.finish was not initialized to false"
)
}
r
.
Finish
(
1
,
1
,
1
)
if
h
.
finish
!=
true
{
t
.
Errorf
(
"ReportHandler.Finish was not called"
)
}
// create a test for testing... hahahahaha
test
:=
rtest
.
Test
{}
// test Reporter.TestStart
if
h
.
testStart
!=
false
{
t
.
Errorf
(
"MockHandler.testStart was not initialized to false"
)
}
r
.
TestStart
(
test
)
if
h
.
testStart
!=
true
{
t
.
Errorf
(
"ReportHandler.TestStart was not called"
)
}
// test Reporter.TestFinish
if
h
.
testFinish
!=
false
{
t
.
Errorf
(
"MockHandler.testFinish was not initialized to false"
)
}
r
.
TestFinish
(
test
,
rtest
.
Result
{})
if
h
.
testFinish
!=
true
{
t
.
Errorf
(
"ReportHandler.TestFinish was not called"
)
}
// test Reporter.LoadTestsFailed
if
h
.
loadTestsFailed
!=
false
{
t
.
Errorf
(
"MockHandler.loadTestsFailed was not initialized to false"
)
}
r
.
LoadTestsFailed
(
nil
)
if
h
.
loadTestsFailed
!=
true
{
t
.
Errorf
(
"ReportHandler.LoadTestsFailed was not called"
)
}
// test Reporter.LoadTestFailed
if
h
.
loadTestFailed
!=
false
{
t
.
Errorf
(
"MockHandler.loadTestFailed was not initialized to false"
)
}
r
.
LoadTestFailed
(
""
,
nil
)
if
h
.
loadTestFailed
!=
true
{
t
.
Errorf
(
"ReportHandler.LoadTestFailed was not called"
)
}
}