-
Notifications
You must be signed in to change notification settings - Fork 34
/
checkers_test.go
44 lines (37 loc) · 1003 Bytes
/
checkers_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
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package loggo_test
import (
"fmt"
"time"
gc "gopkg.in/check.v1"
)
func Between(start, end time.Time) gc.Checker {
if end.Before(start) {
return &betweenChecker{end, start}
}
return &betweenChecker{start, end}
}
type betweenChecker struct {
start, end time.Time
}
func (checker *betweenChecker) Info() *gc.CheckerInfo {
info := gc.CheckerInfo{
Name: "Between",
Params: []string{"obtained"},
}
return &info
}
func (checker *betweenChecker) Check(params []interface{}, names []string) (result bool, error string) {
when, ok := params[0].(time.Time)
if !ok {
return false, "obtained value type must be time.Time"
}
if when.Before(checker.start) {
return false, fmt.Sprintf("obtained time %q is before start time %q", when, checker.start)
}
if when.After(checker.end) {
return false, fmt.Sprintf("obtained time %q is after end time %q", when, checker.end)
}
return true, ""
}