Newer
Older
spb "code.fbi.h-da.de/cocsn/api/go/gosdn/southbound"
"code.fbi.h-da.de/cocsn/gosdn/interfaces/transport"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/path"
"code.fbi.h-da.de/cocsn/gosdn/nucleus/util/proto"
"code.fbi.h-da.de/cocsn/yang-models/generated/openconfig"
"github.com/google/uuid"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/ygot/ytypes"
)
func TestOpenConfig_Id(t *testing.T) {
type fields struct {
schema *ytypes.Schema
id uuid.UUID
}
tests := []struct {
name string
fields fields
want uuid.UUID
}{
{
name: "default",
fields: fields{
},
want: ocUUID,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
oc := &OpenConfig{
schema: tt.fields.schema,
id: tt.fields.id,
if got := oc.ID(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ID() = %v, want %v", got, tt.want)
}
})
}
}
func TestOpenConfig_SbiIdentifier(t *testing.T) {
type fields struct {
}
tests := []struct {
name string
fields fields
want string
}{
{name: "default", fields: fields{}, want: "openconfig"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
oc := &OpenConfig{
schema: tt.fields.schema,
id: tt.fields.id,
}
if got := oc.SbiIdentifier(); got != tt.want {
t.Errorf("SbiIdentifier() = %v, want %v", got, tt.want)
}
})
}
}
func TestOpenConfig_Schema(t *testing.T) {
schema, err := openconfig.Schema()
if err != nil {
t.Error(err)
}
type fields struct {
}
tests := []struct {
name string
fields fields
want *ytypes.Schema
}{
{name: "default", fields: fields{}, want: schema},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
oc := &OpenConfig{
schema: tt.fields.schema,
id: tt.fields.id,
}
got := oc.Schema().SchemaTree
if !reflect.DeepEqual(got, tt.want.SchemaTree) {
t.Errorf("Schema() = %v, want %v", got, tt.want)
}
})
}
}
func Test_unmarshal(t *testing.T) {
type args struct {
path string
opt []ytypes.UnmarshalOpt
}
tests := []struct {
name string
args args
wantErr bool
}{
{
path: "../test/proto/resp-interfaces-interface-arista-ceos",
path: "../test/proto/resp-interfaces-arista-ceos",
goStruct: &openconfig.Device{},
opt: []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}},
},
wantErr: false,
},
{
path: "../test/proto/resp-interfaces-arista-ceos",
goStruct: &openconfig.Device{},
opt: nil,
},
wantErr: true,
},
{
goStruct: &openconfig.Device{},
opt: []ytypes.UnmarshalOpt{&ytypes.IgnoreExtraFields{}},
},
wantErr: false,
},
{
goStruct: &openconfig.Device{},
opt: nil,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resp := &gpb.GetResponse{}
err := proto.Read(tt.args.path, resp)
fields := path.ToStrings(resp.Notification[0].Update[0].Path)
bytes := resp.Notification[0].Update[0].Val.GetJsonIetfVal()
oc := NewSBI(spb.Type_OPENCONFIG)
if err := unmarshal(oc.Schema(), bytes, fields, tt.args.goStruct, tt.args.opt...); err != nil {
if !tt.wantErr {
t.Errorf("unmarshal() error = %v, wantErr %v", err, tt.wantErr)
}
return
}
if tt.args.goStruct.(*openconfig.Device).Interfaces == nil && tt.args.opt != nil {
t.Errorf("unmarshal() error: field Interfaces must not be nil")
}
})
}
}