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/06/15 15:52:25 UTC
[plc4x] branch develop updated: test(plc4go/cbus): fix NPE in connection test
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 7207004beb test(plc4go/cbus): fix NPE in connection test
7207004beb is described below
commit 7207004beb2f26d58219c428fd1f94a3d24b2784
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Thu Jun 15 17:52:19 2023 +0200
test(plc4go/cbus): fix NPE in connection test
---
plc4go/internal/cbus/Connection_test.go | 39 +++++++++++++++++++--------------
1 file changed, 23 insertions(+), 16 deletions(-)
diff --git a/plc4go/internal/cbus/Connection_test.go b/plc4go/internal/cbus/Connection_test.go
index 1e9909b41e..a3ed268adc 100644
--- a/plc4go/internal/cbus/Connection_test.go
+++ b/plc4go/internal/cbus/Connection_test.go
@@ -1767,16 +1767,16 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
tracer tracer.Tracer
}
tests := []struct {
- name string
- fields fields
- setup func(t *testing.T, fields *fields)
+ name string
+ fields fields
+ setup func(t *testing.T, fields *fields)
+ manipulator func(t *testing.T, connection *Connection)
}{
{
name: "just start",
- setup: func(t *testing.T, fields *fields) {
+ manipulator: func(t *testing.T, connection *Connection) {
_options := testutils.EnrichOptionsWithOptionsForTesting(t)
-
- fields.DefaultConnection = _default.NewDefaultConnection(nil, _options...)
+ connection.DefaultConnection = _default.NewDefaultConnection(connection, _options...)
},
},
{
@@ -1784,32 +1784,30 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
setup: func(t *testing.T, fields *fields) {
_options := testutils.EnrichOptionsWithOptionsForTesting(t)
- defaultConnection := _default.NewDefaultConnection(nil, _options...)
- defaultConnection.SetConnected(true)
- fields.DefaultConnection = defaultConnection
-
codec := NewMessageCodec(nil, _options...)
codec.monitoredMMIs = make(chan readWriteModel.CALReply, 1)
codec.monitoredSALs = make(chan readWriteModel.MonitoredSAL, 1)
go func() {
- codec.monitoredMMIs <- nil
- codec.monitoredSALs <- nil
+ codec.monitoredMMIs <- readWriteModel.NewCALReplyShort(0, nil, nil, nil)
+ codec.monitoredSALs <- readWriteModel.NewMonitoredSAL(0, nil)
}()
t.Cleanup(func() {
assert.NoError(t, codec.Disconnect())
})
fields.messageCodec = codec
},
+ manipulator: func(t *testing.T, connection *Connection) {
+ _options := testutils.EnrichOptionsWithOptionsForTesting(t)
+ defaultConnection := _default.NewDefaultConnection(connection, _options...)
+ defaultConnection.SetConnected(true)
+ connection.DefaultConnection = defaultConnection
+ },
},
{
name: "just start and feed",
setup: func(t *testing.T, fields *fields) {
_options := testutils.EnrichOptionsWithOptionsForTesting(t)
- defaultConnection := _default.NewDefaultConnection(nil, _options...)
- defaultConnection.SetConnected(true)
- fields.DefaultConnection = defaultConnection
-
fields.subscribers = []*Subscriber{NewSubscriber(nil, options.WithCustomLogger(testutils.ProduceTestingLogger(t)))}
codec := NewMessageCodec(nil, _options...)
written := make(chan struct{})
@@ -1826,6 +1824,12 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
})
fields.messageCodec = codec
},
+ manipulator: func(t *testing.T, connection *Connection) {
+ _options := testutils.EnrichOptionsWithOptionsForTesting(t)
+ defaultConnection := _default.NewDefaultConnection(connection, _options...)
+ defaultConnection.SetConnected(true)
+ connection.DefaultConnection = defaultConnection
+ },
},
}
for _, tt := range tests {
@@ -1841,6 +1845,9 @@ func TestConnection_startSubscriptionHandler(t *testing.T) {
tracer: tt.fields.tracer,
log: testutils.ProduceTestingLogger(t),
}
+ if tt.manipulator != nil {
+ tt.manipulator(t, c)
+ }
c.startSubscriptionHandler()
})
}