-
Notifications
You must be signed in to change notification settings - Fork 2
/
Node_test.go
64 lines (55 loc) · 1.21 KB
/
Node_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
62
63
64
package dot
import (
"math"
"testing"
"github.com/wwmoraes/dot/dottest"
)
func TestNode_String(t *testing.T) {
graph, err := New()
if err != nil {
t.Fatal("graph is nil, expected a valid instance")
}
n1 := graph.Node("n1")
if got, want := dottest.MustGetSerializableString(t, n1), `"n1";`; got != want {
t.Errorf("got [%v] want [%v]", got, want)
}
}
func TestNode_WriteTo(t *testing.T) {
tests := []struct {
name string
limit int
wantErr error
wantString string
}{
{
name: "zero data written",
limit: 0,
wantErr: dottest.ErrLimit,
wantString: "",
},
{
name: "partially written - node ID",
limit: 1,
wantErr: dottest.ErrLimit,
wantString: `"n1"`,
},
{
name: "fully written",
limit: math.MaxInt32,
wantErr: nil,
wantString: `"n1"[label="test"];`,
},
}
graph, err := New()
if err != nil {
t.Fatal("graph is nil, expected a valid instance")
}
node := graph.Node("n1")
node.SetAttributeString("label", "test")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
wantN := int64(len(tt.wantString))
dottest.TestByteWrite(t, node, tt.limit, tt.wantErr, wantN, tt.wantString)
})
}
}