-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode_test.go
More file actions
49 lines (43 loc) · 1.09 KB
/
Copy pathnode_test.go
File metadata and controls
49 lines (43 loc) · 1.09 KB
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
package ssp
import (
"fmt"
"testing"
"github.com/affo/ssp/values"
"github.com/google/go-cmp/cmp"
)
type dumbCollector struct {
vs []values.Value
}
func (c *dumbCollector) Collect(v values.Value) {
c.vs = append(c.vs, v)
}
func Test_Node(t *testing.T) {
o := NewNode(func(collector Collector, v values.Value) error {
i := v.Int64()
collector.Collect(values.New(i * 1))
collector.Collect(values.New(i * 2))
collector.Collect(values.New(i * 3))
collector.Collect(values.New(i * 4))
return nil
})
c := &dumbCollector{}
if err := o.Do(c, values.New(int64(1))); err != nil {
t.Fatal(err)
}
var got []int64
for _, v := range c.vs {
got = append(got, v.Int64())
}
if diff := cmp.Diff([]int64{1, 2, 3, 4}, got); diff != "" {
t.Errorf("unexpected result -want/+got:\n\t%s", diff)
}
}
func Test_Node_Error(t *testing.T) {
o := NewNode(func(collector Collector, v values.Value) error {
return fmt.Errorf("an error")
})
// Pass at least 1 value to trigger the error above.
if err := o.Do(&dumbCollector{}, values.New(int64(1))); err == nil {
t.Fatal("expected error got none")
}
}