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 ( ...@@ -7,9 +7,7 @@ import (
"testing" "testing"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" 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" 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" "code.fbi.h-da.de/danet/gosdn/controller/store"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper" "github.com/spf13/viper"
...@@ -32,7 +30,7 @@ func Test_GetIds(t *testing.T) { ...@@ -32,7 +30,7 @@ func Test_GetIds(t *testing.T) {
} }
func ensureFilesForTestsAreRemoved() { func ensureFilesForTestsAreRemoved() {
ensureStoreFileForTestsIsRemoved(store.SbiFilenameSuffix) ensureStoreFileForTestsIsRemoved(store.PluginFilenameSuffix)
ensureStoreFileForTestsIsRemoved(store.NetworkElementFilenameSuffix) ensureStoreFileForTestsIsRemoved(store.NetworkElementFilenameSuffix)
} }
...@@ -59,11 +57,7 @@ func ensureStoreFileForTestsIsRemoved(storeName string) { ...@@ -59,11 +57,7 @@ func ensureStoreFileForTestsIsRemoved(storeName string) {
func Test_AddPnd(t *testing.T) { func Test_AddPnd(t *testing.T) {
defer ensureFilesForTestsAreRemoved() defer ensureFilesForTestsAreRemoved()
sbi, err := nucleus.NewSBI(spb.Type_TYPE_OPENCONFIG) resp, err := AddPnd(context.TODO(), bufnet, "test", "test pnd")
if err != nil {
t.Errorf("AddPnd() error = %v", err)
}
resp, err := AddPnd(context.TODO(), bufnet, "test", "test pnd", sbi.ID().String())
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
......
...@@ -10,6 +10,8 @@ import ( ...@@ -10,6 +10,8 @@ import (
"code.fbi.h-da.de/danet/gosdn/api/go/gosdn/conflict" "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/conflict"
cpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/core" 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" ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac" apb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/rbac"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport" tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
...@@ -121,12 +123,12 @@ func bootstrapUnitTest() { ...@@ -121,12 +123,12 @@ func bootstrapUnitTest() {
}, },
}) })
sbi := &nucleus.OpenConfig{} plugin := &mocks.Plugin{}
mockNetworkElement := &mocks.NetworkElement{} mockNetworkElement := &mocks.NetworkElement{}
mockNetworkElement.On("SBI").Return(sbi) mockNetworkElement.On("Plugin").Return(plugin)
mockNetworkElement.On("ID").Return(mneUUID) 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("Name").Return("openconfig")
mockNetworkElement.On("TransportAddress").Return("127.0.0.1:6030") mockNetworkElement.On("TransportAddress").Return("127.0.0.1:6030")
mockNetworkElement.On("GetMetadata").Return(conflict.Metadata{ResourceVersion: 0}) mockNetworkElement.On("GetMetadata").Return(conflict.Metadata{ResourceVersion: 0})
...@@ -145,7 +147,7 @@ func bootstrapUnitTest() { ...@@ -145,7 +147,7 @@ func bootstrapUnitTest() {
mockPnd.On("NetworkElements").Return([]networkelement.NetworkElement{ mockPnd.On("NetworkElements").Return([]networkelement.NetworkElement{
&nucleus.CommonNetworkElement{ &nucleus.CommonNetworkElement{
UUID: mneUUID, UUID: mneUUID,
Plugin: &openconfig.Device{}, Plugin: &mocks.Plugin{},
}, },
}) })
mockPnd.On("GetSBIs").Return([]mocks.SouthboundInterface{}) mockPnd.On("GetSBIs").Return([]mocks.SouthboundInterface{})
...@@ -180,6 +182,9 @@ func bootstrapUnitTest() { ...@@ -180,6 +182,9 @@ func bootstrapUnitTest() {
portService, portService,
routeService, routeService,
appService, appService,
rpb.NewPluginRegistryServiceClient(&grpc.ClientConn{}),
csbi.NewCsbiServiceClient(&grpc.ClientConn{}),
func(u uuid.UUID, c chan networkelement.Details) {},
&mockPnd, &mockPnd,
) )
......
...@@ -9,8 +9,6 @@ import ( ...@@ -9,8 +9,6 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/change" "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/nucleus/types"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/southbound"
ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd" ppb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/pnd"
spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound" spb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/southbound"
tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport" tpb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/transport"
...@@ -18,10 +16,9 @@ import ( ...@@ -18,10 +16,9 @@ import (
"code.fbi.h-da.de/danet/gosdn/controller/mocks" "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/forks/goarista/gnmi"
"code.fbi.h-da.de/danet/gosdn/models/generated/openconfig" "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" gpb "github.com/openconfig/gnmi/proto/gnmi"
"github.com/openconfig/goyang/pkg/yang"
"github.com/openconfig/ygot/ygot" "github.com/openconfig/ygot/ygot"
"github.com/openconfig/ygot/ytypes"
"github.com/stretchr/testify/mock" "github.com/stretchr/testify/mock"
) )
...@@ -106,7 +103,7 @@ func TestGnmi_Capabilities(t *testing.T) { ...@@ -106,7 +103,7 @@ func TestGnmi_Capabilities(t *testing.T) {
func TestGnmi_Close(t *testing.T) { func TestGnmi_Close(t *testing.T) {
type fields struct { 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 RespChan chan *gpb.SubscribeResponse
} }
tests := []struct { tests := []struct {
...@@ -217,56 +214,50 @@ func TestGnmi_Get(t *testing.T) { ...@@ -217,56 +214,50 @@ func TestGnmi_Get(t *testing.T) {
} }
func TestGnmi_ProcessResponse(t *testing.T) { func TestGnmi_ProcessResponse(t *testing.T) {
type fields struct {
Sbi southbound.SouthboundInterface
}
type args struct { type args struct {
path string path string
root interface{}
} }
tests := []struct { tests := []struct {
name string name string
fields fields
args args args args
wantErr bool wantErr bool
}{ }{
{ {
name: "Interfaces Interface", name: "Interfaces Interface",
fields: fields{Sbi: &OpenConfig{}},
args: args{ args: args{
path: "../test/proto/resp-interfaces-interface-arista-ceos", path: "../test/proto/resp-interfaces-interface-arista-ceos",
root: &openconfig.Device{},
}, },
wantErr: false, wantErr: false,
}, },
{ {
name: "Interfaces Wildcard", name: "Interfaces Wildcard",
fields: fields{Sbi: &OpenConfig{}},
args: args{ args: args{
path: "../test/proto/resp-interfaces-wildcard", path: "../test/proto/resp-interfaces-wildcard",
root: &openconfig.Device{},
}, },
wantErr: false, wantErr: false,
}, },
{ {
name: "Root", name: "Root",
fields: fields{Sbi: &OpenConfig{}},
args: args{ args: args{
path: "../test/proto/resp-full-node-arista-ceos", path: "../test/proto/resp-full-node-arista-ceos",
root: &openconfig.Device{},
}, },
wantErr: false, wantErr: false,
}, },
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
networkElementModel, err := openconfigPlugin.NewDeviceModel()
if err != nil {
t.Errorf("ProcessResponse() error = %v", err)
}
g := &Gnmi{ g := &Gnmi{
SetNode: tt.fields.Sbi.SetNode, SetNode: networkElementModel.SetNode,
Unmarshal: tt.fields.Sbi.(*OpenConfig).Unmarshal, Unmarshal: networkElementModel.Unmarshal,
} }
s := tt.fields.Sbi.Schema()
resp := gnmiMessages[tt.args.path] 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) t.Errorf("ProcessResponse() error = %v, wantErr %v", err, tt.wantErr)
} }
}) })
...@@ -388,21 +379,16 @@ func TestGnmi_Set(t *testing.T) { ...@@ -388,21 +379,16 @@ func TestGnmi_Set(t *testing.T) {
} }
func TestGnmi_Subscribe(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 { type args struct {
ctx context.Context ctx context.Context
params []string params []string
} }
tests := []struct { tests := []struct {
name string name string
fields fields
args args args args
wantErr bool wantErr bool
}{ }{
{name: "nil client", fields: fields{}, args: args{}, wantErr: true}, {name: "nil client", args: args{}, wantErr: true},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
...@@ -415,23 +401,15 @@ func TestGnmi_Subscribe(t *testing.T) { ...@@ -415,23 +401,15 @@ func TestGnmi_Subscribe(t *testing.T) {
} }
func TestGnmi_Type(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 { tests := []struct {
name string name string
fields fields want string
want string
}{ }{
{name: "dummy", fields: fields{}, want: "gnmi"}, {name: "dummy", want: "gnmi"},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
g := &Gnmi{ g := &Gnmi{}
SetNode: tt.fields.SetNode,
RespChan: tt.fields.RespChan,
}
if got := g.Type(); got != tt.want { if got := g.Type(); got != tt.want {
t.Errorf("Type() = %v, want %v", 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