From 7ebb519cd0c3089e293fcb646066da4885c037b6 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Thu, 27 Jul 2023 16:21:27 -0600 Subject: [PATCH] Started lockable_test.go --- lockable.go | 11 +++++++++++ lockable_test.go | 13 +++++++++++++ signal.go | 12 ++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 lockable_test.go diff --git a/lockable.go b/lockable.go index 321895f..d9988bd 100644 --- a/lockable.go +++ b/lockable.go @@ -86,6 +86,12 @@ func LoadLockableExt(ctx *Context, data []byte) (Extension, error) { return &ext, nil } + + +func (ext *LockableExt) HandleLinkSignal(ctx *Context, source NodeID, node *Node, signal LinkSignal) { + ctx.Log.Logf("lockable", "LINK_SIGNAL: %+v", signal) +} + func (ext *LockableExt) Process(ctx *Context, source NodeID, node *Node, signal Signal) { ctx.Log.Logf("signal", "LOCKABLE_PROCESS: %s", node.ID) @@ -121,6 +127,11 @@ func (ext *LockableExt) Process(ctx *Context, source NodeID, node *Node, signal } } case Direct: + switch sig := signal.(type) { + case LinkSignal: + ext.HandleLinkSignal(ctx, source, node, sig) + default: + } default: } } diff --git a/lockable_test.go b/lockable_test.go new file mode 100644 index 0000000..ed8029c --- /dev/null +++ b/lockable_test.go @@ -0,0 +1,13 @@ +package graphvent + +import ( + "testing" +) + +func TestLockableLink(t *testing.T) { + ctx := logTestContext(t, []string{"lockable", "signal"}) + LockableType := NodeType("TEST_LOCKABLE") + err := ctx.RegisterNodeType(LockableType, []ExtType{LockableExtType}) + fatalErr(t, err) +} + diff --git a/signal.go b/signal.go index 030945d..ec25568 100644 --- a/signal.go +++ b/signal.go @@ -98,6 +98,18 @@ func NewStatusSignal(status string, source NodeID) StatusSignal { } } +type LinkSignal struct { + IDSignal + State string `json:"state"` +} + +func NewLinkSignal(state string, source NodeID) LinkSignal { + return LinkSignal{ + IDSignal: NewIDSignal("link", Direct, source), + State: state, + } +} + type StartChildSignal struct { IDSignal Action string `json:"action"`