diff --git a/nucleus/principalNetworkDomain_test.go b/nucleus/principalNetworkDomain_test.go index 6ff0f9327387933ef5dbfe92a2fb944182b7aa87..24db614600b220d5f585b1133138c210c6a8a4db 100644 --- a/nucleus/principalNetworkDomain_test.go +++ b/nucleus/principalNetworkDomain_test.go @@ -1,14 +1,16 @@ package nucleus import ( + "errors" + "reflect" + "testing" + "code.fbi.h-da.de/cocsn/gosdn/mocks" "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" - "errors" + "github.com/google/uuid" "github.com/openconfig/ygot/ygot" "github.com/stretchr/testify/mock" - "reflect" - "testing" ) func TestNewPND(t *testing.T) { @@ -657,7 +659,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { func Test_pndImplementation_GetDevice(t *testing.T) { p := newPnd() - d, err := NewDevice(sbi, &GnmiTransportOptions{}) + d, err := NewDevice(sbi, &GnmiTransportOptions{}, "") if err != nil { t.Error(err) return @@ -702,6 +704,56 @@ func Test_pndImplementation_GetDevice(t *testing.T) { } } +func Test_pndImplementation_GetDeviceByName(t *testing.T) { + p := newPnd() + d, err := NewDevice(sbi, &GnmiTransportOptions{}, "my-device") + if err != nil { + t.Error(err) + return + } + if err = p.addDevice(d); err != nil { + t.Error(err) + return + } + type args struct { + name string + } + tests := []struct { + name string + args args + want ygot.GoStruct + wantErr bool + }{ + { + name: "default", + args: args{name: d.Name}, + want: sbi.Schema().Root, + wantErr: false, + }, + { + name: "device not found", + args: args{name: "test-device"}, + want: nil, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + foundDevice, err := p.getDeviceByName(tt.args.name) + if (err != nil) != tt.wantErr { + t.Errorf("GetDeviceByName() error = %v, wantErr %v", err, tt.wantErr) + return + } + if foundDevice != nil { + if !reflect.DeepEqual(foundDevice.GoStruct, tt.want) { + t.Errorf("GetDeviceByName() got = %v, want %v", foundDevice.GoStruct, tt.want) + } + } + + }) + } +} + func Test_pndImplementation_Confirm(t *testing.T) { tests := []struct { name string