forked from k1LoW/runn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.go
61 lines (53 loc) · 1.14 KB
/
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
package runn
import (
"context"
"fmt"
)
const testRunnerKey = "test"
type testRunner struct {
operator *operator
}
type condFalseError struct {
cond string
tree string
}
func newCondFalseError(cond, tree string) *condFalseError {
return &condFalseError{
cond: cond,
tree: tree,
}
}
func (fe *condFalseError) Error() string {
tree := SprintMultilinef(" %s\n", "%s", fe.tree)
return fmt.Sprintf("condition is not true\n\nCondition:\n%s", tree)
}
func newTestRunner(o *operator) (*testRunner, error) {
return &testRunner{
operator: o,
}, nil
}
func (rnr *testRunner) Run(ctx context.Context, cond string, first bool) error {
store := rnr.operator.store.toMap()
store[storeIncludedKey] = rnr.operator.included
if first {
store[storePreviousKey] = rnr.operator.store.latest()
} else {
store[storePreviousKey] = rnr.operator.store.previous()
store[storeCurrentKey] = rnr.operator.store.latest()
}
t, err := buildTree(cond, store)
if err != nil {
return err
}
tf, err := EvalCond(cond, store)
if err != nil {
return err
}
if !tf {
return newCondFalseError(cond, t)
}
if first {
rnr.operator.record(nil)
}
return nil
}