You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2023/04/11 12:43:27 UTC
[plc4x] branch develop updated: test(plc4go/cbus): add test for browse query
This is an automated email from the ASF dual-hosted git repository.
sruehl pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/plc4x.git
The following commit(s) were added to refs/heads/develop by this push:
new 115216ee99 test(plc4go/cbus): add test for browse query
115216ee99 is described below
commit 115216ee99cbff017bb829102093b4abecaebe92
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Tue Apr 11 14:43:18 2023 +0200
test(plc4go/cbus): add test for browse query
---
plc4go/internal/cbus/Browser_test.go | 96 +++++++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 2 deletions(-)
diff --git a/plc4go/internal/cbus/Browser_test.go b/plc4go/internal/cbus/Browser_test.go
index c712773695..22e94d6d66 100644
--- a/plc4go/internal/cbus/Browser_test.go
+++ b/plc4go/internal/cbus/Browser_test.go
@@ -23,6 +23,7 @@ import (
"context"
"fmt"
apiModel "github.com/apache/plc4x/plc4go/pkg/api/model"
+ readWriteModel "github.com/apache/plc4x/plc4go/protocols/cbus/readwrite/model"
"github.com/apache/plc4x/plc4go/spi"
_default "github.com/apache/plc4x/plc4go/spi/default"
"github.com/apache/plc4x/plc4go/spi/transports"
@@ -52,7 +53,98 @@ func TestBrowser_BrowseQuery(t *testing.T) {
want apiModel.PlcResponseCode
want1 []apiModel.PlcBrowseItem
}{
- // TODO: Add test cases.
+ {
+ name: "invalid address",
+ want: apiModel.PlcResponseCode_INVALID_ADDRESS,
+ },
+ {
+ name: "non responding browse",
+ fields: fields{
+ DefaultBrowser: nil,
+ connection: func() spi.PlcConnection {
+ transport := test.NewTransport()
+ transportUrl := url.URL{Scheme: "test"}
+ transportInstance, err := transport.CreateTransportInstance(transportUrl, nil)
+ if err != nil {
+ t.Error(err)
+ t.FailNow()
+ return nil
+ }
+ type MockState uint8
+ const (
+ RESET MockState = iota
+ APPLICATION_FILTER_1
+ APPLICATION_FILTER_2
+ INTERFACE_OPTIONS_3
+ INTERFACE_OPTIONS_1_PUN
+ INTERFACE_OPTIONS_1
+ DONE
+ )
+ currentState := atomic.Value{}
+ currentState.Store(RESET)
+ transportInstance.(*test.TransportInstance).SetWriteInterceptor(func(transportInstance *test.TransportInstance, data []byte) {
+ switch currentState.Load().(MockState) {
+ case RESET:
+ t.Log("Dispatching reset echo")
+ transportInstance.FillReadBuffer([]byte("~~~\r"))
+ currentState.Store(APPLICATION_FILTER_1)
+ case APPLICATION_FILTER_1:
+ t.Log("Dispatching app1 echo and confirm")
+ transportInstance.FillReadBuffer([]byte("@A32100FF\r"))
+ transportInstance.FillReadBuffer([]byte("322100AD\r\n"))
+ currentState.Store(APPLICATION_FILTER_2)
+ case APPLICATION_FILTER_2:
+ t.Log("Dispatching app2 echo and confirm")
+ transportInstance.FillReadBuffer([]byte("@A32200FF\r"))
+ transportInstance.FillReadBuffer([]byte("322200AC\r\n"))
+ currentState.Store(INTERFACE_OPTIONS_3)
+ case INTERFACE_OPTIONS_3:
+ t.Log("Dispatching interface 3 echo and confirm")
+ transportInstance.FillReadBuffer([]byte("@A342000A\r"))
+ transportInstance.FillReadBuffer([]byte("3242008C\r\n"))
+ currentState.Store(INTERFACE_OPTIONS_1_PUN)
+ case INTERFACE_OPTIONS_1_PUN:
+ t.Log("Dispatching interface 1 PUN echo and confirm???")
+ transportInstance.FillReadBuffer([]byte("@A3410079\r"))
+ transportInstance.FillReadBuffer([]byte("3241008D\r\n"))
+ currentState.Store(INTERFACE_OPTIONS_1)
+ case INTERFACE_OPTIONS_1:
+ t.Log("Dispatching interface 1 echo and confirm???")
+ transportInstance.FillReadBuffer([]byte("@A3300079\r"))
+ transportInstance.FillReadBuffer([]byte("3230009E\r\n"))
+ currentState.Store(DONE)
+ case DONE:
+ t.Log("Dispatching 3 MMI segments")
+ transportInstance.FillReadBuffer([]byte("86020200F900FF0094120006000000000000000008000000000000000000CA\r\n"))
+ transportInstance.FillReadBuffer([]byte("86020200F900FF580000000000000000000000000000000000000000000026\r\n"))
+ transportInstance.FillReadBuffer([]byte("86020200F700FFB00000000000000000000000000000000000000000D0\r\n"))
+ }
+ })
+ err = transport.AddPreregisteredInstances(transportUrl, transportInstance)
+ if err != nil {
+ t.Error(err)
+ t.FailNow()
+ return nil
+ }
+ connectionConnectResult := <-NewDriver().GetConnection(transportUrl, map[string]transports.Transport{"test": transport}, map[string][]string{})
+ if err := connectionConnectResult.GetErr(); err != nil {
+ t.Error(err)
+ t.FailNow()
+ return nil
+ }
+ connection := connectionConnectResult.GetConnection()
+ return connection.(spi.PlcConnection)
+ }(),
+ sequenceCounter: 0,
+ },
+ args: args{
+ ctx: context.Background(),
+ interceptor: nil,
+ queryName: "testQuery",
+ query: NewUnitInfoQuery(readWriteModel.NewUnitAddress(2), nil, 1),
+ },
+ want: apiModel.PlcResponseCode_OK,
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -62,7 +154,7 @@ func TestBrowser_BrowseQuery(t *testing.T) {
sequenceCounter: tt.fields.sequenceCounter,
}
got, got1 := m.BrowseQuery(tt.args.ctx, tt.args.interceptor, tt.args.queryName, tt.args.query)
- assert.Equalf(t, tt.want, got, "BrowseQuery(%v, %v, %v, %v)", tt.args.ctx, tt.args.interceptor, tt.args.queryName, tt.args.query)
+ assert.Equalf(t, tt.want, got, "BrowseQuery(%v, func(), %v,\n%v\n)", tt.args.ctx, tt.args.queryName, tt.args.query)
assert.Equalf(t, tt.want1, got1, "BrowseQuery(%v, %v, %v, %v)", tt.args.ctx, tt.args.interceptor, tt.args.queryName, tt.args.query)
})
}