Skip to content
Snippets Groups Projects

Let user set a name for a device or autogenerate it

Merged Ghost User requested to merge istaester/autogenerate-device-names into develop
1 file
+ 56
4
Compare changes
  • Side-by-side
  • Inline
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
Loading