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/05 12:23:25 UTC

[plc4x] branch develop updated: test(plc4go/spi): add tests for discovery options

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 8947839cf3 test(plc4go/spi): add tests for discovery options
8947839cf3 is described below

commit 8947839cf3ac00c00b2e863ccebae69c52f7b9ed
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Fri May 5 14:23:16 2023 +0200

    test(plc4go/spi): add tests for discovery options
---
 plc4go/spi/options/DiscoveryOption.go      |  12 +-
 plc4go/spi/options/DiscoveryOption_test.go | 618 +++++++++++++++++++++++++++++
 plc4go/spi/options/Option_test.go          |  41 ++
 3 files changed, 665 insertions(+), 6 deletions(-)

diff --git a/plc4go/spi/options/DiscoveryOption.go b/plc4go/spi/options/DiscoveryOption.go
index 65ab4254cb..c9873f90e9 100644
--- a/plc4go/spi/options/DiscoveryOption.go
+++ b/plc4go/spi/options/DiscoveryOption.go
@@ -65,7 +65,7 @@ func FilterDiscoveryOptionsProtocol(options []WithDiscoveryOption) []DiscoveryOp
 	var filtered []DiscoveryOptionProtocol
 	for _, option := range options {
 		switch option.(type) {
-		case DiscoveryOptionProtocol:
+		case discoveryOptionProtocol:
 			filtered = append(filtered, option.(DiscoveryOptionProtocol))
 		}
 	}
@@ -76,7 +76,7 @@ func FilterDiscoveryOptionsTransport(options []WithDiscoveryOption) []DiscoveryO
 	var filtered []DiscoveryOptionTransport
 	for _, option := range options {
 		switch option.(type) {
-		case DiscoveryOptionTransport:
+		case discoveryOptionTransport:
 			filtered = append(filtered, option.(DiscoveryOptionTransport))
 		}
 	}
@@ -87,7 +87,7 @@ func FilterDiscoveryOptionsDeviceName(options []WithDiscoveryOption) []Discovery
 	var filtered []DiscoveryOptionDeviceName
 	for _, option := range options {
 		switch option.(type) {
-		case DiscoveryOptionDeviceName:
+		case discoveryOptionDeviceName:
 			filtered = append(filtered, option.(DiscoveryOptionDeviceName))
 		}
 	}
@@ -98,7 +98,7 @@ func FilterDiscoveryOptionsLocalAddress(options []WithDiscoveryOption) []Discove
 	var filtered []DiscoveryOptionLocalAddress
 	for _, option := range options {
 		switch option.(type) {
-		case DiscoveryOptionLocalAddress:
+		case discoveryOptionLocalAddress:
 			filtered = append(filtered, option.(DiscoveryOptionLocalAddress))
 		}
 	}
@@ -109,7 +109,7 @@ func FilterDiscoveryOptionsRemoteAddress(options []WithDiscoveryOption) []Discov
 	var filtered []DiscoveryOptionRemoteAddress
 	for _, option := range options {
 		switch option.(type) {
-		case DiscoveryOptionRemoteAddress:
+		case discoveryOptionRemoteAddress:
 			filtered = append(filtered, option.(DiscoveryOptionRemoteAddress))
 		}
 	}
@@ -120,7 +120,7 @@ func FilterDiscoveryOptionProtocolSpecific(options []WithDiscoveryOption) []Disc
 	var filtered []DiscoveryOptionProtocolSpecific
 	for _, option := range options {
 		switch option := option.(type) {
-		case DiscoveryOptionProtocolSpecific:
+		case discoveryOptionProtocolSpecific:
 			filtered = append(filtered, option)
 		}
 	}
diff --git a/plc4go/spi/options/DiscoveryOption_test.go b/plc4go/spi/options/DiscoveryOption_test.go
new file mode 100644
index 0000000000..e1de50f726
--- /dev/null
+++ b/plc4go/spi/options/DiscoveryOption_test.go
@@ -0,0 +1,618 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package options
+
+import (
+	"reflect"
+	"testing"
+)
+
+func TestFilterDiscoveryOptionProtocolSpecific(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionProtocolSpecific
+	}{
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionDeviceName{},
+			}},
+			want: []DiscoveryOptionProtocolSpecific{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionProtocolSpecific{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionProtocolSpecific(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionProtocolSpecific() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestFilterDiscoveryOptionsDeviceName(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionDeviceName
+	}{
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionDeviceName{},
+				discoveryOptionDeviceName{},
+			}},
+			want: []DiscoveryOptionDeviceName{
+				discoveryOptionDeviceName{},
+				discoveryOptionDeviceName{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionsDeviceName(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionsDeviceName() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestFilterDiscoveryOptionsLocalAddress(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionLocalAddress
+	}{
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionLocalAddress{},
+				discoveryOptionLocalAddress{},
+			}},
+			want: []DiscoveryOptionLocalAddress{
+				discoveryOptionLocalAddress{},
+				discoveryOptionLocalAddress{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionsLocalAddress(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionsLocalAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestFilterDiscoveryOptionsProtocol(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionProtocol
+	}{
+
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionProtocol{},
+				discoveryOptionProtocol{},
+			}},
+			want: []DiscoveryOptionProtocol{
+				discoveryOptionProtocol{},
+				discoveryOptionProtocol{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionsProtocol(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionsProtocol() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestFilterDiscoveryOptionsRemoteAddress(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionRemoteAddress
+	}{
+
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionRemoteAddress{},
+				discoveryOptionRemoteAddress{},
+			}},
+			want: []DiscoveryOptionRemoteAddress{
+				discoveryOptionRemoteAddress{},
+				discoveryOptionRemoteAddress{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionsRemoteAddress(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionsRemoteAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestFilterDiscoveryOptionsTransport(t *testing.T) {
+	type args struct {
+		options []WithDiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want []DiscoveryOptionTransport
+	}{
+
+		{
+			name: "nothing",
+		},
+		{
+			name: "find it",
+			args: args{options: []WithDiscoveryOption{
+				discoveryOptionProtocolSpecific{},
+				discoveryOptionTransport{},
+				discoveryOptionTransport{},
+			}},
+			want: []DiscoveryOptionTransport{
+				discoveryOptionTransport{},
+				discoveryOptionTransport{},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := FilterDiscoveryOptionsTransport(tt.args.options); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("FilterDiscoveryOptionsTransport() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionDeviceName(t *testing.T) {
+	type args struct {
+		deviceName string
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{deviceName: "something"},
+			want: discoveryOptionDeviceName{deviceName: "something"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := WithDiscoveryOptionDeviceName(tt.args.deviceName); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("WithDiscoveryOptionDeviceName() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionLocalAddress(t *testing.T) {
+	type args struct {
+		localAddress string
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{localAddress: "something"},
+			want: discoveryOptionLocalAddress{localAddress: "something"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := WithDiscoveryOptionLocalAddress(tt.args.localAddress); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("WithDiscoveryOptionLocalAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionProtocol(t *testing.T) {
+	type args struct {
+		protocolName string
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{protocolName: "something"},
+			want: discoveryOptionProtocol{protocolName: "something"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := WithDiscoveryOptionProtocol(tt.args.protocolName); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("WithDiscoveryOptionProtocol() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionProtocolSpecific(t *testing.T) {
+	type args struct {
+		key   string
+		value any
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{key: "something", value: "something"},
+			want: discoveryOptionProtocolSpecific{key: "something", value: "something"},
+		},
+	}
+	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) {
+				t.Errorf("WithDiscoveryOptionProtocolSpecific() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionRemoteAddress(t *testing.T) {
+	type args struct {
+		remoteAddress string
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{remoteAddress: "something"},
+			want: discoveryOptionRemoteAddress{remoteAddress: "something"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := WithDiscoveryOptionRemoteAddress(tt.args.remoteAddress); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("WithDiscoveryOptionRemoteAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func TestWithDiscoveryOptionTransport(t *testing.T) {
+	type args struct {
+		transportName string
+	}
+	tests := []struct {
+		name string
+		args args
+		want WithDiscoveryOption
+	}{
+		{
+			name: "something",
+			args: args{transportName: "something"},
+			want: discoveryOptionTransport{transportName: "something"},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := WithDiscoveryOptionTransport(tt.args.transportName); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("WithDiscoveryOptionTransport() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionDeviceName_GetDeviceName(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		deviceName      string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				deviceName: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionDeviceName{
+				discoveryOption: tt.fields.discoveryOption,
+				deviceName:      tt.fields.deviceName,
+			}
+			if got := d.GetDeviceName(); got != tt.want {
+				t.Errorf("GetDeviceName() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionLocalAddress_GetLocalAddress(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		localAddress    string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				localAddress: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionLocalAddress{
+				discoveryOption: tt.fields.discoveryOption,
+				localAddress:    tt.fields.localAddress,
+			}
+			if got := d.GetLocalAddress(); got != tt.want {
+				t.Errorf("GetLocalAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionProtocolSpecific_GetKey(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		key             string
+		value           any
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				key: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionProtocolSpecific{
+				discoveryOption: tt.fields.discoveryOption,
+				key:             tt.fields.key,
+				value:           tt.fields.value,
+			}
+			if got := d.GetKey(); got != tt.want {
+				t.Errorf("GetKey() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionProtocolSpecific_GetValue(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		key             string
+		value           any
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   any
+	}{
+		{
+			name: "something",
+			fields: fields{
+				value: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionProtocolSpecific{
+				discoveryOption: tt.fields.discoveryOption,
+				key:             tt.fields.key,
+				value:           tt.fields.value,
+			}
+			if got := d.GetValue(); !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("GetValue() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionProtocol_GetProtocolName(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		protocolName    string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				protocolName: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionProtocol{
+				discoveryOption: tt.fields.discoveryOption,
+				protocolName:    tt.fields.protocolName,
+			}
+			if got := d.GetProtocolName(); got != tt.want {
+				t.Errorf("GetProtocolName() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionRemoteAddress_GetRemoteAddress(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		remoteAddress   string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				remoteAddress: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionRemoteAddress{
+				discoveryOption: tt.fields.discoveryOption,
+				remoteAddress:   tt.fields.remoteAddress,
+			}
+			if got := d.GetRemoteAddress(); got != tt.want {
+				t.Errorf("GetRemoteAddress() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOptionTransport_GetTransportName(t *testing.T) {
+	type fields struct {
+		discoveryOption discoveryOption
+		transportName   string
+	}
+	tests := []struct {
+		name   string
+		fields fields
+		want   string
+	}{
+		{
+			name: "something",
+			fields: fields{
+				transportName: "something",
+			},
+			want: "something",
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := discoveryOptionTransport{
+				discoveryOption: tt.fields.discoveryOption,
+				transportName:   tt.fields.transportName,
+			}
+			if got := d.GetTransportName(); got != tt.want {
+				t.Errorf("GetTransportName() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
+
+func Test_discoveryOption_isDiscoveryOption(t *testing.T) {
+	tests := []struct {
+		name string
+		want bool
+	}{
+		{
+			name: "something",
+			want: true,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			di := discoveryOption{}
+			if got := di.isDiscoveryOption(); got != tt.want {
+				t.Errorf("isDiscoveryOption() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
diff --git a/plc4go/spi/options/Option_test.go b/plc4go/spi/options/Option_test.go
new file mode 100644
index 0000000000..e4eb95fad5
--- /dev/null
+++ b/plc4go/spi/options/Option_test.go
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package options
+
+import "testing"
+
+func TestOption_isOption(t *testing.T) {
+	tests := []struct {
+		name string
+		want bool
+	}{
+		{
+			want: true,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			op := Option{}
+			if got := op.isOption(); got != tt.want {
+				t.Errorf("isOption() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}