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/05/08 08:52:36 UTC

[plc4x] branch develop updated: test(plc4go/spi): add test for tcp transport

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 a55586c131 test(plc4go/spi): add test for tcp transport
a55586c131 is described below

commit a55586c131f888b467fdaf903ba1408590e36b90
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon May 8 10:52:26 2023 +0200

    test(plc4go/spi): add test for tcp transport
---
 plc4go/spi/options/DiscoveryOption_test.go         |  28 +-
 plc4go/spi/transports/TransportInstance_test.go    |   8 +-
 plc4go/spi/transports/serial/Transport_test.go     |  17 +-
 plc4go/spi/transports/tcp/Transport.go             |  14 +-
 plc4go/spi/transports/tcp/Transport_test.go        | 294 +++++++++++++++++++--
 plc4go/spi/transports/test/Transport_test.go       |  21 +-
 plc4go/spi/transports/udp/Transport_test.go        |  19 +-
 .../spi/transports/utils/TransportLogger_test.go   |  11 +-
 8 files changed, 340 insertions(+), 72 deletions(-)

diff --git a/plc4go/spi/options/DiscoveryOption_test.go b/plc4go/spi/options/DiscoveryOption_test.go
index e1de50f726..871e180059 100644
--- a/plc4go/spi/options/DiscoveryOption_test.go
+++ b/plc4go/spi/options/DiscoveryOption_test.go
@@ -20,7 +20,7 @@
 package options
 
 import (
-	"reflect"
+	"github.com/stretchr/testify/assert"
 	"testing"
 )
 
@@ -51,7 +51,7 @@ func TestFilterDiscoveryOptionProtocolSpecific(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionProtocolSpecific(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionProtocolSpecific(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionProtocolSpecific() = %v, want %v", got, tt.want)
 			}
 		})
@@ -85,7 +85,7 @@ func TestFilterDiscoveryOptionsDeviceName(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionsDeviceName(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionsDeviceName(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionsDeviceName() = %v, want %v", got, tt.want)
 			}
 		})
@@ -119,7 +119,7 @@ func TestFilterDiscoveryOptionsLocalAddress(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionsLocalAddress(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionsLocalAddress(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionsLocalAddress() = %v, want %v", got, tt.want)
 			}
 		})
@@ -154,7 +154,7 @@ func TestFilterDiscoveryOptionsProtocol(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionsProtocol(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionsProtocol(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionsProtocol() = %v, want %v", got, tt.want)
 			}
 		})
@@ -189,7 +189,7 @@ func TestFilterDiscoveryOptionsRemoteAddress(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionsRemoteAddress(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionsRemoteAddress(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionsRemoteAddress() = %v, want %v", got, tt.want)
 			}
 		})
@@ -224,7 +224,7 @@ func TestFilterDiscoveryOptionsTransport(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := FilterDiscoveryOptionsTransport(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+			if got := FilterDiscoveryOptionsTransport(tt.args.options); !assert.Equal(t, tt.want, got) {
 				t.Errorf("FilterDiscoveryOptionsTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -248,7 +248,7 @@ func TestWithDiscoveryOptionDeviceName(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionDeviceName(tt.args.deviceName); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionDeviceName(tt.args.deviceName); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionDeviceName() = %v, want %v", got, tt.want)
 			}
 		})
@@ -272,7 +272,7 @@ func TestWithDiscoveryOptionLocalAddress(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionLocalAddress(tt.args.localAddress); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionLocalAddress(tt.args.localAddress); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionLocalAddress() = %v, want %v", got, tt.want)
 			}
 		})
@@ -296,7 +296,7 @@ func TestWithDiscoveryOptionProtocol(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionProtocol(tt.args.protocolName); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionProtocol(tt.args.protocolName); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionProtocol() = %v, want %v", got, tt.want)
 			}
 		})
@@ -321,7 +321,7 @@ func TestWithDiscoveryOptionProtocolSpecific(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionProtocolSpecific(tt.args.key, tt.args.value); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionProtocolSpecific(tt.args.key, tt.args.value); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionProtocolSpecific() = %v, want %v", got, tt.want)
 			}
 		})
@@ -345,7 +345,7 @@ func TestWithDiscoveryOptionRemoteAddress(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionRemoteAddress(tt.args.remoteAddress); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionRemoteAddress(tt.args.remoteAddress); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionRemoteAddress() = %v, want %v", got, tt.want)
 			}
 		})
@@ -369,7 +369,7 @@ func TestWithDiscoveryOptionTransport(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithDiscoveryOptionTransport(tt.args.transportName); !reflect.DeepEqual(got, tt.want) {
+			if got := WithDiscoveryOptionTransport(tt.args.transportName); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithDiscoveryOptionTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -497,7 +497,7 @@ func Test_discoveryOptionProtocolSpecific_GetValue(t *testing.T) {
 				key:             tt.fields.key,
 				value:           tt.fields.value,
 			}
-			if got := d.GetValue(); !reflect.DeepEqual(got, tt.want) {
+			if got := d.GetValue(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("GetValue() = %v, want %v", got, tt.want)
 			}
 		})
diff --git a/plc4go/spi/transports/TransportInstance_test.go b/plc4go/spi/transports/TransportInstance_test.go
index bb8b307bd4..7d99bd2332 100644
--- a/plc4go/spi/transports/TransportInstance_test.go
+++ b/plc4go/spi/transports/TransportInstance_test.go
@@ -23,7 +23,7 @@ import (
 	"bufio"
 	"bytes"
 	"context"
-	"reflect"
+	"github.com/stretchr/testify/assert"
 	"testing"
 )
 
@@ -43,7 +43,7 @@ func TestNewDefaultBufferedTransportInstance(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewDefaultBufferedTransportInstance(tt.args.defaultBufferedTransportInstanceRequirements); !reflect.DeepEqual(got, tt.want) {
+			if got := NewDefaultBufferedTransportInstance(tt.args.defaultBufferedTransportInstanceRequirements); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewDefaultBufferedTransportInstance() = %v, want %v", got, tt.want)
 			}
 		})
@@ -284,7 +284,7 @@ func Test_defaultBufferedTransportInstance_PeekReadableBytes(t *testing.T) {
 				t.Errorf("PeekReadableBytes() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("PeekReadableBytes() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -355,7 +355,7 @@ func Test_defaultBufferedTransportInstance_Read(t *testing.T) {
 				t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("Read() got = %v, want %v", got, tt.want)
 			}
 		})
diff --git a/plc4go/spi/transports/serial/Transport_test.go b/plc4go/spi/transports/serial/Transport_test.go
index bdd2cf0a05..4cb04a9ac5 100644
--- a/plc4go/spi/transports/serial/Transport_test.go
+++ b/plc4go/spi/transports/serial/Transport_test.go
@@ -22,10 +22,10 @@ package serial
 import (
 	"bufio"
 	"github.com/apache/plc4x/plc4go/spi/transports"
+	"github.com/stretchr/testify/assert"
 	"io"
 	"net"
 	"net/url"
-	"reflect"
 	"testing"
 )
 
@@ -34,11 +34,14 @@ func TestNewTransport(t *testing.T) {
 		name string
 		want *Transport
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: &Transport{},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransport(); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransport(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -61,7 +64,7 @@ func TestNewTransportInstance(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransportInstance(tt.args.serialPortName, tt.args.baudRate, tt.args.connectTimeout, tt.args.transport); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransportInstance(tt.args.serialPortName, tt.args.baudRate, tt.args.connectTimeout, tt.args.transport); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransportInstance() = %v, want %v", got, tt.want)
 			}
 		})
@@ -166,7 +169,7 @@ func TestTransportInstance_GetReader(t *testing.T) {
 				serialPort:                       tt.fields.serialPort,
 				reader:                           tt.fields.reader,
 			}
-			if got := m.GetReader(); !reflect.DeepEqual(got, tt.want) {
+			if got := m.GetReader(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("GetReader() = %v, want %v", got, tt.want)
 			}
 		})
@@ -303,7 +306,7 @@ func TestTransport_CreateTransportInstance(t *testing.T) {
 				t.Errorf("CreateTransportInstance() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstance() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -332,7 +335,7 @@ func TestTransport_CreateTransportInstanceForLocalAddress(t *testing.T) {
 				t.Errorf("CreateTransportInstanceForLocalAddress() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstanceForLocalAddress() got = %v, want %v", got, tt.want)
 			}
 		})
diff --git a/plc4go/spi/transports/tcp/Transport.go b/plc4go/spi/transports/tcp/Transport.go
index 43f25bdaf0..b84e8e7932 100644
--- a/plc4go/spi/transports/tcp/Transport.go
+++ b/plc4go/spi/transports/tcp/Transport.go
@@ -57,16 +57,9 @@ func (m Transport) CreateTransportInstance(transportUrl url.URL, options map[str
 			address = val
 		} else if val, ok := match["hostname"]; ok && len(val) > 0 {
 			address = val
-		} else {
-			return nil, errors.New("missing hostname or ip to connect")
-		}
+		} // Note: the regex ensures that it is either ip or hostname
 		if val, ok := match["port"]; ok && len(val) > 0 {
-			portVal, err := strconv.Atoi(val)
-			if err != nil {
-				return nil, errors.Wrap(err, "error setting port")
-			} else {
-				port = portVal
-			}
+			port, _ = strconv.Atoi(val) // Note: the regex ensures that this is always a valid number
 		} else if val, ok := options["defaultTcpPort"]; ok && len(val) > 0 {
 			portVal, err := strconv.Atoi(val[0])
 			if err != nil {
@@ -124,6 +117,9 @@ func (m *TransportInstance) Connect() error {
 }
 
 func (m *TransportInstance) ConnectWithContext(ctx context.Context) error {
+	if m.RemoteAddress == nil {
+		return errors.New("Required remote address missing")
+	}
 	var err error
 	var d net.Dialer
 	m.tcpConn, err = d.DialContext(ctx, "tcp", m.RemoteAddress.String())
diff --git a/plc4go/spi/transports/tcp/Transport_test.go b/plc4go/spi/transports/tcp/Transport_test.go
index 9096f0a3ba..3e819581fa 100644
--- a/plc4go/spi/transports/tcp/Transport_test.go
+++ b/plc4go/spi/transports/tcp/Transport_test.go
@@ -22,10 +22,12 @@ package tcp
 import (
 	"bufio"
 	"context"
+	"fmt"
 	"github.com/apache/plc4x/plc4go/spi/transports"
+	"github.com/stretchr/testify/assert"
+	"golang.org/x/net/nettest"
 	"net"
 	"net/url"
-	"reflect"
 	"testing"
 )
 
@@ -40,11 +42,18 @@ func TestNewTcpTransportInstance(t *testing.T) {
 		args args
 		want *TransportInstance
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: func() *TransportInstance {
+				ti := &TransportInstance{}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTcpTransportInstance(tt.args.remoteAddress, tt.args.connectTimeout, tt.args.transport); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTcpTransportInstance(tt.args.remoteAddress, tt.args.connectTimeout, tt.args.transport); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTcpTransportInstance() = %v, want %v", got, tt.want)
 			}
 		})
@@ -56,11 +65,14 @@ func TestNewTransport(t *testing.T) {
 		name string
 		want *Transport
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: &Transport{},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransport(); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransport(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -82,7 +94,38 @@ func TestTransportInstance_Close(t *testing.T) {
 		fields  fields
 		wantErr bool
 	}{
-		// TODO: Add test cases.
+		{
+			name: "close it (no conn)",
+		},
+		{
+			name: "close it (broken connection)",
+			fields: fields{
+				tcpConn: &net.TCPConn{},
+			},
+			wantErr: true,
+		},
+		{
+			name: "close it",
+			fields: fields{
+				tcpConn: func() *net.TCPConn {
+					listener, err := nettest.NewLocalListener("tcp")
+					assert.NoError(t, err)
+					t.Cleanup(func() {
+						assert.NoError(t, listener.Close())
+					})
+					go func() {
+						_, _ = listener.Accept()
+					}()
+					tcp, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
+					assert.NoError(t, err)
+					t.Cleanup(func() {
+						// As we already closed the connection with the whole method this should error
+						assert.Error(t, tcp.Close())
+					})
+					return tcp
+				}(),
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -117,7 +160,10 @@ func TestTransportInstance_Connect(t *testing.T) {
 		fields  fields
 		wantErr bool
 	}{
-		// TODO: Add test cases.
+		{
+			name:    "connect it (failing)",
+			wantErr: true,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -156,7 +202,31 @@ func TestTransportInstance_ConnectWithContext(t *testing.T) {
 		args    args
 		wantErr bool
 	}{
-		// TODO: Add test cases.
+		{
+			name: "connect it",
+			fields: fields{
+				RemoteAddress: func() *net.TCPAddr {
+					listener, err := nettest.NewLocalListener("tcp")
+					assert.NoError(t, err)
+					t.Cleanup(func() {
+						assert.NoError(t, listener.Close())
+					})
+					go func() {
+						_, _ = listener.Accept()
+					}()
+					return listener.Addr().(*net.TCPAddr)
+				}(),
+			},
+			args: args{ctx: context.Background()},
+		},
+		{
+			name: "connect it (non existing address)",
+			fields: fields{
+				RemoteAddress: &net.TCPAddr{},
+			},
+			args:    args{ctx: context.Background()},
+			wantErr: true,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -191,7 +261,9 @@ func TestTransportInstance_GetReader(t *testing.T) {
 		fields fields
 		want   *bufio.Reader
 	}{
-		// TODO: Add test cases.
+		{
+			name: "get it",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -204,7 +276,7 @@ func TestTransportInstance_GetReader(t *testing.T) {
 				tcpConn:                          tt.fields.tcpConn,
 				reader:                           tt.fields.reader,
 			}
-			if got := m.GetReader(); !reflect.DeepEqual(got, tt.want) {
+			if got := m.GetReader(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("GetReader() = %v, want %v", got, tt.want)
 			}
 		})
@@ -226,7 +298,9 @@ func TestTransportInstance_IsConnected(t *testing.T) {
 		fields fields
 		want   bool
 	}{
-		// TODO: Add test cases.
+		{
+			name: "check it",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -261,7 +335,18 @@ func TestTransportInstance_String(t *testing.T) {
 		fields fields
 		want   string
 	}{
-		// TODO: Add test cases.
+		{
+			name: "get it",
+			want: "tcp:<nil>",
+		},
+		{
+			name: "get it too",
+			fields: fields{
+				LocalAddress:  &net.TCPAddr{IP: net.IPv4(1, 2, 3, 4), Port: 5},
+				RemoteAddress: &net.TCPAddr{IP: net.IPv4(6, 7, 8, 9), Port: 10},
+			},
+			want: "tcp:1.2.3.4:5->6.7.8.9:10",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -300,7 +385,38 @@ func TestTransportInstance_Write(t *testing.T) {
 		args    args
 		wantErr bool
 	}{
-		// TODO: Add test cases.
+		{
+			name:    "write it (failing)",
+			wantErr: true,
+		},
+		{
+			name: "write it (failing with con)",
+			fields: fields{
+				tcpConn: &net.TCPConn{},
+			},
+			wantErr: true,
+		},
+		{
+			name: "write it",
+			fields: fields{
+				tcpConn: func() *net.TCPConn {
+					listener, err := nettest.NewLocalListener("tcp")
+					assert.NoError(t, err)
+					t.Cleanup(func() {
+						assert.NoError(t, listener.Close())
+					})
+					go func() {
+						_, _ = listener.Accept()
+					}()
+					tcp, err := net.DialTCP("tcp", nil, listener.Addr().(*net.TCPAddr))
+					assert.NoError(t, err)
+					t.Cleanup(func() {
+						assert.NoError(t, tcp.Close())
+					})
+					return tcp
+				}(),
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -331,7 +447,140 @@ func TestTransport_CreateTransportInstance(t *testing.T) {
 		want    transports.TransportInstance
 		wantErr bool
 	}{
-		// TODO: Add test cases.
+		{
+			name: "Create it",
+			want: func() transports.TransportInstance {
+				tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", "", 0))
+				assert.NoError(t, err)
+				ti := &TransportInstance{
+					transport:      NewTransport(),
+					RemoteAddress:  tcpAddr,
+					ConnectTimeout: 1000,
+				}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
+		{
+			name: "Create it with transport url",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1:123"},
+			},
+			want: func() transports.TransportInstance {
+				tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", "127.0.0.1", 123))
+				assert.NoError(t, err)
+				ti := &TransportInstance{
+					transport:      NewTransport(),
+					RemoteAddress:  tcpAddr,
+					ConnectTimeout: 1000,
+				}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
+		{
+			name: "Create it with transport url (named host)",
+			args: args{
+				transportUrl: url.URL{Host: "localhost:123"},
+			},
+			want: func() transports.TransportInstance {
+				tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", "localhost", 123))
+				assert.NoError(t, err)
+				ti := &TransportInstance{
+					transport:      NewTransport(),
+					RemoteAddress:  tcpAddr,
+					ConnectTimeout: 1000,
+				}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
+		{
+			name: "Create it with transport url (without port)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1"},
+			},
+			wantErr: true,
+		},
+		{
+			name: "Create it with transport url (with nonsense port)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1:banana"},
+			},
+			wantErr: true,
+		},
+		{
+			name: "Create it with transport url (with default port)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1"},
+				options: map[string][]string{
+					"defaultTcpPort": {"123"},
+				},
+			},
+			want: func() transports.TransportInstance {
+				tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", "127.0.0.1", 123))
+				assert.NoError(t, err)
+				ti := &TransportInstance{
+					transport:      NewTransport(),
+					RemoteAddress:  tcpAddr,
+					ConnectTimeout: 1000,
+				}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
+		{
+			name: "Create it with transport url (with broken default port)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1"},
+				options: map[string][]string{
+					"defaultTcpPort": {"default"},
+				},
+			},
+			wantErr: true,
+		},
+		{
+			name: "Create it with transport url (with default port and connection timeout)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1"},
+				options: map[string][]string{
+					"defaultTcpPort":  {"123"},
+					"connect-timeout": {"123"},
+				},
+			},
+			want: func() transports.TransportInstance {
+				tcpAddr, err := net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", "127.0.0.1", 123))
+				assert.NoError(t, err)
+				ti := &TransportInstance{
+					transport:      NewTransport(),
+					RemoteAddress:  tcpAddr,
+					ConnectTimeout: 123,
+				}
+				ti.DefaultBufferedTransportInstance = transports.NewDefaultBufferedTransportInstance(ti)
+				return ti
+			}(),
+		},
+		{
+			name: "Create it with transport url (with default port and connection timeout broken)",
+			args: args{
+				transportUrl: url.URL{Host: "127.0.0.1"},
+				options: map[string][]string{
+					"defaultTcpPort":  {"123"},
+					"connect-timeout": {"banana"},
+				},
+			},
+			wantErr: true,
+		},
+		{
+			name: "Create it with unresolvable host",
+			args: args{
+				transportUrl: url.URL{Host: "plc4xhostnothere"},
+				options: map[string][]string{
+					"defaultTcpPort": {"123"},
+				},
+			},
+			wantErr: true,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -341,7 +590,7 @@ func TestTransport_CreateTransportInstance(t *testing.T) {
 				t.Errorf("CreateTransportInstance() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstance() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -353,7 +602,10 @@ func TestTransport_GetTransportCode(t *testing.T) {
 		name string
 		want string
 	}{
-		// TODO: Add test cases.
+		{
+			name: "get it",
+			want: "tcp",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -370,7 +622,10 @@ func TestTransport_GetTransportName(t *testing.T) {
 		name string
 		want string
 	}{
-		// TODO: Add test cases.
+		{
+			name: "get it",
+			want: "TCP/IP Socket Transport",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
@@ -387,7 +642,10 @@ func TestTransport_String(t *testing.T) {
 		name string
 		want string
 	}{
-		// TODO: Add test cases.
+		{
+			name: "get the string",
+			want: "tcp(TCP/IP Socket Transport)",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
diff --git a/plc4go/spi/transports/test/Transport_test.go b/plc4go/spi/transports/test/Transport_test.go
index d37f1cae53..7e184301a5 100644
--- a/plc4go/spi/transports/test/Transport_test.go
+++ b/plc4go/spi/transports/test/Transport_test.go
@@ -23,8 +23,8 @@ import (
 	"bufio"
 	"context"
 	"github.com/apache/plc4x/plc4go/spi/transports"
+	"github.com/stretchr/testify/assert"
 	"net/url"
-	"reflect"
 	"testing"
 )
 
@@ -33,11 +33,16 @@ func TestNewTransport(t *testing.T) {
 		name string
 		want *Transport
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: &Transport{
+				preregisteredInstances: map[url.URL]transports.TransportInstance{},
+			},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransport(); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransport(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -57,7 +62,7 @@ func TestNewTransportInstance(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransportInstance(tt.args.transport); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransportInstance(tt.args.transport); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransportInstance() = %v, want %v", got, tt.want)
 			}
 		})
@@ -189,7 +194,7 @@ func TestTransportInstance_DrainWriteBuffer(t *testing.T) {
 				transport:        tt.fields.transport,
 				writeInterceptor: tt.fields.writeInterceptor,
 			}
-			if got := m.DrainWriteBuffer(tt.args.numBytes); !reflect.DeepEqual(got, tt.want) {
+			if got := m.DrainWriteBuffer(tt.args.numBytes); !assert.Equal(t, tt.want, got) {
 				t.Errorf("DrainWriteBuffer() = %v, want %v", got, tt.want)
 			}
 		})
@@ -396,7 +401,7 @@ func TestTransportInstance_PeekReadableBytes(t *testing.T) {
 				t.Errorf("PeekReadableBytes() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("PeekReadableBytes() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -437,7 +442,7 @@ func TestTransportInstance_Read(t *testing.T) {
 				t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("Read() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -597,7 +602,7 @@ func TestTransport_CreateTransportInstance(t *testing.T) {
 				t.Errorf("CreateTransportInstance() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstance() got = %v, want %v", got, tt.want)
 			}
 		})
diff --git a/plc4go/spi/transports/udp/Transport_test.go b/plc4go/spi/transports/udp/Transport_test.go
index 1ece1addac..10fba75736 100644
--- a/plc4go/spi/transports/udp/Transport_test.go
+++ b/plc4go/spi/transports/udp/Transport_test.go
@@ -23,9 +23,9 @@ import (
 	"bufio"
 	"context"
 	"github.com/apache/plc4x/plc4go/spi/transports"
+	"github.com/stretchr/testify/assert"
 	"net"
 	"net/url"
-	"reflect"
 	"testing"
 )
 
@@ -34,11 +34,14 @@ func TestNewTransport(t *testing.T) {
 		name string
 		want *Transport
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: &Transport{},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransport(); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransport(); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransport() = %v, want %v", got, tt.want)
 			}
 		})
@@ -62,7 +65,7 @@ func TestNewTransportInstance(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransportInstance(tt.args.localAddress, tt.args.remoteAddress, tt.args.connectTimeout, tt.args.soReUse, tt.args.transport); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransportInstance(tt.args.localAddress, tt.args.remoteAddress, tt.args.connectTimeout, tt.args.soReUse, tt.args.transport); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransportInstance() = %v, want %v", got, tt.want)
 			}
 		})
@@ -331,7 +334,7 @@ func TestTransportInstance_PeekReadableBytes(t *testing.T) {
 				t.Errorf("PeekReadableBytes() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("PeekReadableBytes() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -376,7 +379,7 @@ func TestTransportInstance_Read(t *testing.T) {
 				t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("Read() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -478,7 +481,7 @@ func TestTransport_CreateTransportInstance(t *testing.T) {
 				t.Errorf("CreateTransportInstance() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstance() got = %v, want %v", got, tt.want)
 			}
 		})
@@ -507,7 +510,7 @@ func TestTransport_CreateTransportInstanceForLocalAddress(t *testing.T) {
 				t.Errorf("CreateTransportInstanceForLocalAddress() error = %v, wantErr %v", err, tt.wantErr)
 				return
 			}
-			if !reflect.DeepEqual(got, tt.want) {
+			if !assert.Equal(t, tt.want, got) {
 				t.Errorf("CreateTransportInstanceForLocalAddress() got = %v, want %v", got, tt.want)
 			}
 		})
diff --git a/plc4go/spi/transports/utils/TransportLogger_test.go b/plc4go/spi/transports/utils/TransportLogger_test.go
index 50c5373b27..35a023aa3b 100644
--- a/plc4go/spi/transports/utils/TransportLogger_test.go
+++ b/plc4go/spi/transports/utils/TransportLogger_test.go
@@ -21,8 +21,8 @@ package utils
 
 import (
 	"github.com/rs/zerolog"
+	"github.com/stretchr/testify/assert"
 	"io"
-	"reflect"
 	"testing"
 )
 
@@ -36,11 +36,14 @@ func TestNewTransportLogger(t *testing.T) {
 		args args
 		want *TransportLogger
 	}{
-		// TODO: Add test cases.
+		{
+			name: "create it",
+			want: &TransportLogger{},
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := NewTransportLogger(tt.args.source, tt.args.options...); !reflect.DeepEqual(got, tt.want) {
+			if got := NewTransportLogger(tt.args.source, tt.args.options...); !assert.Equal(t, tt.want, got) {
 				t.Errorf("NewTransportLogger() = %v, want %v", got, tt.want)
 			}
 		})
@@ -155,7 +158,7 @@ func TestWithLogger(t *testing.T) {
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
-			if got := WithLogger(tt.args.log); !reflect.DeepEqual(got, tt.want) {
+			if got := WithLogger(tt.args.log); !assert.Equal(t, tt.want, got) {
 				t.Errorf("WithLogger() = %v, want %v", got, tt.want)
 			}
 		})