graphvent/graph_test.go

49 lines
1.1 KiB
Go

2023-06-18 18:33:17 -06:00
package graphvent
2023-04-08 15:23:40 -06:00
import (
"testing"
"runtime/debug"
2023-06-22 15:50:42 -06:00
badger "github.com/dgraph-io/badger/v3"
2023-04-08 15:23:40 -06:00
)
var SimpleListenerNodeType = NewNodeType("SIMPLE_LISTENER")
2023-07-27 00:30:24 -06:00
2023-08-31 22:31:29 -06:00
func NewSimpleListener(ctx *Context, buffer int) (*Node, *ListenerExt, error) {
2023-07-27 00:30:24 -06:00
listener_extension := NewListenerExt(buffer)
2023-08-31 22:31:29 -06:00
listener, err := NewNode(ctx,
nil,
2023-07-27 11:33:11 -06:00
SimpleListenerNodeType,
10,
nil,
2023-07-27 11:33:11 -06:00
listener_extension,
NewLockableExt(nil))
2023-07-27 00:30:24 -06:00
2023-08-31 22:31:29 -06:00
return listener, listener_extension, err
2023-07-27 00:30:24 -06:00
}
2023-07-25 21:43:15 -06:00
func logTestContext(t * testing.T, components []string) *Context {
db, err := badger.Open(badger.DefaultOptions("").WithInMemory(true))
if err != nil {
t.Fatal(err)
}
2023-07-25 21:43:15 -06:00
ctx, err := NewContext(db, NewConsoleLogger(components))
fatalErr(t, err)
2023-07-27 00:30:24 -06:00
err = ctx.RegisterNodeType(SimpleListenerNodeType, []ExtType{ListenerExtType, LockableExtType})
2023-07-27 00:30:24 -06:00
fatalErr(t, err)
2023-07-25 21:43:15 -06:00
return ctx
}
2023-07-09 14:30:30 -06:00
func testContext(t * testing.T) * Context {
2023-07-27 00:30:24 -06:00
return logTestContext(t, []string{})
}
func fatalErr(t * testing.T, err error) {
if err != nil {
debug.PrintStack()
t.Fatal(err)
}
}