From 8b608265772ba5df13d24071117c694bdfd1212a Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 30 Jun 2023 13:07:12 +0200 Subject: Add session pointer to routing infrastructure It is nearly useless to route a XML element to an appropriate handler function if the latter has no idea how to send responses to the server or the GUI. Passing a pointer to the session solves this issue. --- xmpp/router_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'xmpp/router_test.go') diff --git a/xmpp/router_test.go b/xmpp/router_test.go index ea13712..41484c5 100644 --- a/xmpp/router_test.go +++ b/xmpp/router_test.go @@ -23,9 +23,10 @@ type routerTest struct { // validated. func TestRouter(t *testing.T) { var testpoint int + var s session - factory := func(tp *int, i int) func([]xml.Token) { - return func([]xml.Token) { + factory := func(tp *int, i int) func(*session, []xml.Token) { + return func(*session, []xml.Token) { *tp = i } } @@ -60,7 +61,7 @@ func TestRouter(t *testing.T) { tokens = append(tokens, xml.CopyToken(token)) } - route(tokens, testRouting) + route(&s, tokens, testRouting) if testpoint != v.value { t.Fatalf("XML element was not routed correctly!\n") -- cgit v1.2.3-70-g09d2 From 3dc04660a87e1b9fabeea0e55a8511d80d34a694 Mon Sep 17 00:00:00 2001 From: xengineering Date: Fri, 30 Jun 2023 13:57:52 +0200 Subject: Apply go fmt --- xmpp/element_buffer_test.go | 4 ++-- xmpp/router_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'xmpp/router_test.go') diff --git a/xmpp/element_buffer_test.go b/xmpp/element_buffer_test.go index 113a2c4..af3d5c2 100644 --- a/xmpp/element_buffer_test.go +++ b/xmpp/element_buffer_test.go @@ -11,8 +11,8 @@ import ( // which has to be exactly one XML element and an array of indentation levels // which have to be checked after each token which is parsed. type bufTest struct { - xml string - levels []int + xml string + levels []int } func TestElementBuffer(t *testing.T) { diff --git a/xmpp/router_test.go b/xmpp/router_test.go index 41484c5..b490778 100644 --- a/xmpp/router_test.go +++ b/xmpp/router_test.go @@ -2,8 +2,8 @@ package xmpp import ( "encoding/xml" - "testing" "strings" + "testing" ) // routerTest contains a single test case for the xmpp.router. The XML element @@ -11,8 +11,8 @@ import ( // test variable inside the corresponding unit test. See TestRouter for // details. type routerTest struct { - xml string - value int + xml string + value int } // TestRouter tests the xmpp/router.go file. The central functionality is the -- cgit v1.2.3-70-g09d2