-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtriple_test.go
81 lines (73 loc) · 1.32 KB
/
triple_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package fabric_test
import (
"testing"
"github.com/spy16/fabric"
)
func TestTriple_Validate(suite *testing.T) {
suite.Parallel()
cases := []struct {
title string
triple fabric.Triple
expectErr bool
}{
{
title: "InvalidSourceName",
triple: fabric.Triple{
Source: "?",
},
expectErr: true,
},
{
title: "InvalidPredicateName",
triple: fabric.Triple{
Source: "bob",
Predicate: "",
},
expectErr: true,
},
{
title: "InvalidTarget",
triple: fabric.Triple{
Source: "bob",
Predicate: "knows",
Target: "{",
},
expectErr: true,
},
{
title: "Valid",
triple: fabric.Triple{
Source: "bob",
Predicate: "knows",
Target: "john",
},
},
}
for _, cs := range cases {
suite.Run(cs.title, func(t *testing.T) {
err := cs.triple.Validate()
if err != nil {
if !cs.expectErr {
t.Errorf("unexpected error: %v", err)
return
}
return
}
if cs.expectErr {
t.Error("expecting error, got nil")
}
})
}
}
func TestTriple_String(t *testing.T) {
tri := fabric.Triple{
Source: "Bob",
Predicate: "Knows",
Target: "John",
Weight: 10,
}
expected := "Bob Knows John 10.000000"
if tri.String() != expected {
t.Errorf("expected string to be '%s', got '%s'", expected, tri.String())
}
}