Skip to content
Snippets Groups Projects
Commit 6f5d3cf6 authored by André Sterba's avatar André Sterba
Browse files

Add test for getDeviceByName

parent e0790856
No related branches found
No related tags found
1 merge request!150Let user set a name for a device or autogenerate it
Pipeline #69583 passed with warnings
This commit is part of merge request !150. Comments created here will be created in the context of that merge request.
package nucleus package nucleus
import ( import (
"errors"
"reflect"
"testing"
"code.fbi.h-da.de/cocsn/gosdn/mocks" "code.fbi.h-da.de/cocsn/gosdn/mocks"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig" "code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"errors"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
"reflect"
"testing"
) )
func TestNewPND(t *testing.T) { func TestNewPND(t *testing.T) {
...@@ -657,7 +659,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) { ...@@ -657,7 +659,7 @@ func Test_pndImplementation_ChangeOND(t *testing.T) {
func Test_pndImplementation_GetDevice(t *testing.T) { func Test_pndImplementation_GetDevice(t *testing.T) {
p := newPnd() p := newPnd()
d, err := NewDevice(sbi, &GnmiTransportOptions{}) d, err := NewDevice(sbi, &GnmiTransportOptions{}, "")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
...@@ -702,6 +704,56 @@ func Test_pndImplementation_GetDevice(t *testing.T) { ...@@ -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) { func Test_pndImplementation_Confirm(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment