Skip to content
Snippets Groups Projects
Commit 5281165f authored by Malte Bauch's avatar Malte Bauch
Browse files

WIP: First test case updates

TODO: this commit has to be rebased
parent 5469f4f2
No related branches found
No related tags found
1 merge request!401Change the current gosdn plugin implementation from Go's internal plugin system to hashicorp's go-plugins
Pipeline #121579 failed
......@@ -7,9 +7,7 @@ import (
"testing"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus"
"code.fbi.h-da.de/danet/gosdn/controller/store"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
......@@ -32,7 +30,7 @@ func Test_GetIds(t *testing.T) {
}
func ensureFilesForTestsAreRemoved() {
ensureStoreFileForTestsIsRemoved(store.SbiFilenameSuffix)
ensureStoreFileForTestsIsRemoved(store.PluginFilenameSuffix)
ensureStoreFileForTestsIsRemoved(store.NetworkElementFilenameSuffix)
}
......@@ -59,11 +57,7 @@ func ensureStoreFileForTestsIsRemoved(storeName string) {
func Test_AddPnd(t *testing.T) {
defer ensureFilesForTestsAreRemoved()
sbi, err := nucleus.NewSBI(spb.Type_TYPE_OPENCONFIG)
if err != nil {
t.Errorf("AddPnd() error = %v", err)
}
resp, err := AddPnd(context.TODO(), bufnet, "test", "test pnd", sbi.ID().String())
resp, err := AddPnd(context.TODO(), bufnet, "test", "test pnd")
if err != nil {
t.Error(err)
return
......
......@@ -10,6 +10,8 @@ import (
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/conflict"
cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core"
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/csbi"
rpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin-registry"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
......@@ -121,12 +123,12 @@ func bootstrapUnitTest() {
},
})
sbi := &nucleus.OpenConfig{}
plugin := &mocks.Plugin{}
mockNetworkElement := &mocks.NetworkElement{}
mockNetworkElement.On("SBI").Return(sbi)
mockNetworkElement.On("Plugin").Return(plugin)
mockNetworkElement.On("ID").Return(mneUUID)
mockNetworkElement.On("GetModel").Return(sbi.Schema().Root)
mockNetworkElement.On("GetModel").Return(plugin.Model())
mockNetworkElement.On("Name").Return("openconfig")
mockNetworkElement.On("TransportAddress").Return("127.0.0.1:6030")
mockNetworkElement.On("GetMetadata").Return(conflict.Metadata{ResourceVersion: 0})
......@@ -145,7 +147,7 @@ func bootstrapUnitTest() {
mockPnd.On("NetworkElements").Return([]networkelement.NetworkElement{
&nucleus.CommonNetworkElement{
UUID: mneUUID,
Plugin: &openconfig.Device{},
Plugin: &mocks.Plugin{},
},
})
mockPnd.On("GetSBIs").Return([]mocks.SouthboundInterface{})
......@@ -180,6 +182,9 @@ func bootstrapUnitTest() {
portService,
routeService,
appService,
rpb.NewPluginRegistryServiceClient(&grpc.ClientConn{}),
csbi.NewCsbiServiceClient(&grpc.ClientConn{}),
func(u uuid.UUID, c chan networkelement.Details) {},
&mockPnd,
)
......
......@@ -9,8 +9,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/change"
"code.fbi.h-da.de/danet/gosdn/controller/nucleus/types"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
......@@ -18,10 +16,9 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/mocks"
"code.fbi.h-da.de/danet/gosdn/forks/goarista/gnmi"
"code.fbi.h-da.de/danet/gosdn/models/generated/openconfig"
openconfigPlugin "code.fbi.h-da.de/danet/gosdn/plugins/openconfig"
gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
"github.com/stretchr/testify/mock"
)
......@@ -106,7 +103,7 @@ func TestGnmi_Capabilities(t *testing.T) {
func TestGnmi_Close(t *testing.T) {
type fields struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
SetNode func(path *gpb.Path, value *gpb.TypedValue) error
RespChan chan *gpb.SubscribeResponse
}
tests := []struct {
......@@ -217,56 +214,50 @@ func TestGnmi_Get(t *testing.T) {
}
func TestGnmi_ProcessResponse(t *testing.T) {
type fields struct {
Sbi southbound.SouthboundInterface
}
type args struct {
path string
root interface{}
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{
name: "Interfaces Interface",
fields: fields{Sbi: &OpenConfig{}},
name: "Interfaces Interface",
args: args{
path: "../test/proto/resp-interfaces-interface-arista-ceos",
root: &openconfig.Device{},
},
wantErr: false,
},
{
name: "Interfaces Wildcard",
fields: fields{Sbi: &OpenConfig{}},
name: "Interfaces Wildcard",
args: args{
path: "../test/proto/resp-interfaces-wildcard",
root: &openconfig.Device{},
},
wantErr: false,
},
{
name: "Root",
fields: fields{Sbi: &OpenConfig{}},
name: "Root",
args: args{
path: "../test/proto/resp-full-node-arista-ceos",
root: &openconfig.Device{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
networkElementModel, err := openconfigPlugin.NewDeviceModel()
if err != nil {
t.Errorf("ProcessResponse() error = %v", err)
}
g := &Gnmi{
SetNode: tt.fields.Sbi.SetNode,
Unmarshal: tt.fields.Sbi.(*OpenConfig).Unmarshal,
SetNode: networkElementModel.SetNode,
Unmarshal: networkElementModel.Unmarshal,
}
s := tt.fields.Sbi.Schema()
resp := gnmiMessages[tt.args.path]
if err := g.ProcessResponse(resp, tt.args.root, s); (err != nil) != tt.wantErr {
if err := g.ProcessResponse(resp); (err != nil) != tt.wantErr {
t.Errorf("ProcessResponse() error = %v, wantErr %v", err, tt.wantErr)
}
})
......@@ -388,21 +379,16 @@ func TestGnmi_Set(t *testing.T) {
}
func TestGnmi_Subscribe(t *testing.T) {
type fields struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse
}
type args struct {
ctx context.Context
params []string
}
tests := []struct {
name string
fields fields
args args
wantErr bool
}{
{name: "nil client", fields: fields{}, args: args{}, wantErr: true},
{name: "nil client", args: args{}, wantErr: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
......@@ -415,23 +401,15 @@ func TestGnmi_Subscribe(t *testing.T) {
}
func TestGnmi_Type(t *testing.T) {
type fields struct {
SetNode func(schema *yang.Entry, root interface{}, path *gpb.Path, val interface{}, opts ...ytypes.SetNodeOpt) error
RespChan chan *gpb.SubscribeResponse
}
tests := []struct {
name string
fields fields
want string
name string
want string
}{
{name: "dummy", fields: fields{}, want: "gnmi"},
{name: "dummy", want: "gnmi"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := &Gnmi{
SetNode: tt.fields.SetNode,
RespChan: tt.fields.RespChan,
}
g := &Gnmi{}
if got := g.Type(); got != tt.want {
t.Errorf("Type() = %v, want %v", got, tt.want)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment