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/22 11:10:54 UTC

[plc4x] branch develop updated: test(plc4go/cbus): add test for buffer commons (missing branch coverage)

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 ed67b4a798 test(plc4go/cbus): add test for buffer commons (missing branch coverage)
ed67b4a798 is described below

commit ed67b4a798dbae5bb124a84b5aa2607fedfb5f27
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Mon May 22 13:10:47 2023 +0200

    test(plc4go/cbus): add test for buffer commons (missing branch coverage)
---
 plc4go/spi/utils/bufferCommons_test.go | 82 +++++++++++++++++++++++++++++++---
 1 file changed, 76 insertions(+), 6 deletions(-)

diff --git a/plc4go/spi/utils/bufferCommons_test.go b/plc4go/spi/utils/bufferCommons_test.go
index 70c9124913..02c41490a4 100644
--- a/plc4go/spi/utils/bufferCommons_test.go
+++ b/plc4go/spi/utils/bufferCommons_test.go
@@ -30,9 +30,10 @@ func TestBufferCommons_ExtractAdditionalStringRepresentation(t *testing.T) {
 		readerWriterArgs []WithReaderWriterArgs
 	}
 	tests := []struct {
-		name string
-		args args
-		want string
+		name      string
+		args      args
+		want      string
+		wantPanic bool
 	}{
 		{
 			name: "extract nothing",
@@ -46,9 +47,43 @@ func TestBufferCommons_ExtractAdditionalStringRepresentation(t *testing.T) {
 			},
 			want: "plc4xftw",
 		},
+		{
+			name: "broken arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{},
+				},
+			},
+			wantPanic: true,
+		},
+		{
+			name: "it is as reader arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{WithReaderArgs: withAdditionalStringRepresentation{stringRepresentation: "plc4xftw"}},
+				},
+			},
+			want: "plc4xftw",
+		},
+		{
+			name: "it is as writer arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{WithWriterArgs: withAdditionalStringRepresentation{stringRepresentation: "plc4xftw"}},
+				},
+			},
+			want: "plc4xftw",
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
+			defer func() {
+				if tt.wantPanic {
+					assert.NotNil(t, recover(), "we expected a panic")
+				} else {
+					assert.Nil(t, recover(), "we don't expected a panic")
+				}
+			}()
 			b := BufferCommons{}
 			assert.Equalf(t, tt.want, b.ExtractAdditionalStringRepresentation(tt.args.readerWriterArgs...), "ExtractAdditionalStringRepresentation(%v)", tt.args.readerWriterArgs)
 		})
@@ -60,9 +95,10 @@ func TestBufferCommons_IsToBeRenderedAsList(t *testing.T) {
 		readerWriterArgs []WithReaderWriterArgs
 	}
 	tests := []struct {
-		name string
-		args args
-		want bool
+		name      string
+		args      args
+		want      bool
+		wantPanic bool
 	}{
 		{
 			name: "nope",
@@ -84,9 +120,43 @@ func TestBufferCommons_IsToBeRenderedAsList(t *testing.T) {
 			},
 			want: true,
 		},
+		{
+			name: "broken arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{},
+				},
+			},
+			wantPanic: true,
+		},
+		{
+			name: "it is as reader arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{WithReaderArgs: withRenderAsList{renderAsList: true}},
+				},
+			},
+			want: true,
+		},
+		{
+			name: "it is as writer arg",
+			args: args{
+				readerWriterArgs: []WithReaderWriterArgs{
+					readerWriterArg{WithWriterArgs: withRenderAsList{renderAsList: true}},
+				},
+			},
+			want: true,
+		},
 	}
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
+			defer func() {
+				if tt.wantPanic {
+					assert.NotNil(t, recover(), "we expected a panic")
+				} else {
+					assert.Nil(t, recover(), "we don't expected a panic")
+				}
+			}()
 			b := BufferCommons{}
 			assert.Equalf(t, tt.want, b.IsToBeRenderedAsList(tt.args.readerWriterArgs...), "IsToBeRenderedAsList(%v)", tt.args.readerWriterArgs)
 		})