-
Notifications
You must be signed in to change notification settings - Fork 22
/
types_test.go
56 lines (50 loc) · 1.21 KB
/
types_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
package biscuit
import (
"testing"
"time"
"github.com/biscuit-auth/biscuit-go/v2/datalog"
"github.com/stretchr/testify/require"
)
func TestFromDatalogFact(t *testing.T) {
now := time.Now()
symbolTable := &datalog.SymbolTable{"sym0", "sym1", "var1"}
dlFact := datalog.Fact{
Predicate: datalog.Predicate{
Name: datalog.String(datalog.OFFSET + 0),
Terms: []datalog.Term{
datalog.String(datalog.OFFSET + 1),
datalog.Integer(42),
symbolTable.Insert("foo"),
datalog.Variable(datalog.OFFSET + 2),
datalog.Date(now.Unix()),
datalog.Bytes([]byte("some random bytes")),
datalog.Bool(true),
datalog.Bool(false),
datalog.Set{
symbolTable.Insert("abc"),
datalog.Integer(42),
datalog.String(datalog.OFFSET + 1),
},
},
},
}
fact, err := fromDatalogFact(symbolTable, dlFact)
require.NoError(t, err)
expectedFact := &Fact{
Predicate: Predicate{
Name: "sym0",
IDs: []Term{
String("sym1"),
Integer(42),
String("foo"),
Variable("var1"),
Date(time.Unix(now.Unix(), 0)),
Bytes([]byte("some random bytes")),
Bool(true),
Bool(false),
Set{String("abc"), Integer(42), String("sym1")},
},
},
}
require.Equal(t, expectedFact, fact)
}