work in progess: action handling; start with simple test
This commit is contained in:
parent
4ad87d635c
commit
4c174217d1
1 changed files with 18 additions and 0 deletions
|
@ -4,7 +4,10 @@ import (
|
|||
"fmt"
|
||||
tbase "testing"
|
||||
|
||||
"git.sr.ht/~cco/go-scopes/config"
|
||||
"git.sr.ht/~cco/go-scopes/lib"
|
||||
"git.sr.ht/~cco/go-scopes/lib/action"
|
||||
"git.sr.ht/~cco/go-scopes/lib/context"
|
||||
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||
"git.sr.ht/~cco/go-scopes/testing"
|
||||
)
|
||||
|
@ -14,6 +17,7 @@ func TestUnit(tb *tbase.T) {
|
|||
t.Run("address", AddressTest)
|
||||
t.Run("message", MessageTest)
|
||||
t.Run("payload", PayloadTest)
|
||||
t.Run("action", ActionTest)
|
||||
}
|
||||
|
||||
func AddressTest(t *testing.T) {
|
||||
|
@ -57,3 +61,17 @@ func PayloadTest(t *testing.T) {
|
|||
pl3 := message.PayloadFromJson[map[string]any](`{"activity": "development"}`)
|
||||
t.AssertEqual(fmt.Sprint(pl3), `{"activity":"development"}`)
|
||||
}
|
||||
|
||||
func ActionTest(t *testing.T) {
|
||||
var result struct{ data string }
|
||||
var hdlr lib.ActionHandler = func(act lib.Action) bool {
|
||||
result.data = "done"
|
||||
return true
|
||||
}
|
||||
cfg := config.Base("testing", nil).
|
||||
AddAction("doit", action.Base(hdlr))
|
||||
ctx := context.AppContext(cfg)
|
||||
msg := message.SimpleMessage("doit")
|
||||
lib.HandleMsg(ctx, msg)
|
||||
t.AssertEqual(result.data, "done")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue