vgc UTs part 4
Change-Id: I0e78854fefb8f0ad270a84bc88982f859a0d5995
diff --git a/internal/pkg/application/vnets_test.go b/internal/pkg/application/vnets_test.go
index 8942dbb..5a26bea 100644
--- a/internal/pkg/application/vnets_test.go
+++ b/internal/pkg/application/vnets_test.go
@@ -17,7 +17,10 @@
import (
"context"
+ "encoding/json"
+ "net"
"reflect"
+ "sync"
"testing"
cntlr "voltha-go-controller/internal/pkg/controller"
"voltha-go-controller/internal/pkg/of"
@@ -25,6 +28,7 @@
"voltha-go-controller/internal/test/mocks"
"github.com/golang/mock/gomock"
+ "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore"
"github.com/stretchr/testify/assert"
)
@@ -645,3 +649,248 @@
})
}
}
+
+func TestVoltApplication_RestoreVnetsFromDb(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_RestoreVnetsFromDb",
+ args: args{
+ cntx: context.Background(),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ vnetsToDelete := map[string]bool{}
+ vnetsToDelete["test_name"] = true
+ va := &VoltApplication{
+ VnetsBySvlan: util.NewConcurrentMap(),
+ VnetsToDelete: vnetsToDelete,
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ vnets := map[string]*kvstore.KVPair{}
+ voltVnet.SVlan = of.VlanAny
+ b, err := json.Marshal(voltVnet)
+ if err != nil {
+ panic(err)
+ }
+ vnets["test_device_id"] = &kvstore.KVPair{
+ Key: "test_device_id",
+ Value: b,
+ }
+ dbintf.EXPECT().PutVnet(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ dbintf.EXPECT().GetVnets(tt.args.cntx).Return(vnets, nil)
+ va.RestoreVnetsFromDb(tt.args.cntx)
+ })
+ }
+}
+
+func TestVoltApplication_DeleteDevFlowForDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device *VoltDevice
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_DeleteDevFlowForDevice",
+ args: args{
+ cntx: context.Background(),
+ device: &VoltDevice{
+ Name: test_device,
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ },
+ },
+ },
+ }
+ var voltVnet_DeleteDevFlowForDevice = &VoltVnet{
+ Version: "test_version",
+ VnetConfig: VnetConfig{
+ Name: "test_name",
+ SVlan: of.VlanAny,
+ CVlan: of.VlanAny,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.VnetsByName.Store("4096-4096-0", voltVnet_DeleteDevFlowForDevice)
+ //tt.args.device.ConfiguredVlanForDeviceFlows.SyncMap.Store("4096-4069-0", util.NewConcurrentMap())
+ va.DeleteDevFlowForDevice(tt.args.cntx, tt.args.device)
+ })
+ }
+}
+
+func TestVoltApplication_DelVnetFromPort(t *testing.T) {
+ macAdd, _ := net.ParseMAC("ff:ff:ff:ff:ff:ff")
+ vpv_test := []*VoltPortVnet{
+ {
+ Device: test_device,
+ Port: "test_port",
+ MacAddr: macAdd,
+ VnetName: "test_vnet_name",
+ },
+ }
+ type args struct {
+ cntx context.Context
+ port string
+ vpv *VoltPortVnet
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_DelVnetFromPort",
+ args: args{
+ cntx: context.Background(),
+ port: "test_port",
+ vpv: &VoltPortVnet{
+ Device: test_device,
+ Port: "test_port",
+ MacAddr: macAdd,
+ VnetName: "test_vnet_name",
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ va.VnetsByPort.Store("test_port", vpv_test)
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+ dbintf.EXPECT().DelVpv(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ va.VnetsByName.Store("test_vnet_name", &VoltVnet{
+ Version: "test_version",
+ })
+ va.DelVnetFromPort(tt.args.cntx, tt.args.port, tt.args.vpv)
+ })
+ }
+}
+
+func TestVoltApplication_PushDevFlowForVlan(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ vnet *VoltVnet
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "VoltApplication_PushDevFlowForVlan",
+ args: args{
+ cntx: context.Background(),
+ vnet: &VoltVnet{
+ Version: "test_version",
+ VnetConfig: VnetConfig{
+ DevicesList: []string{"test_serialNum"},
+ SVlan: of.VlanAny,
+ },
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ voltDevice.SerialNum = "test_serialNum"
+ voltDevice.VlanPortStatus.Store(uint16(of.VlanAny), true)
+ voltDevice.Name = test_device
+ va.DevicesDisc.Store(test_device, voltDevice)
+ ga := GetApplication()
+ ga.DevicesDisc.Store(test_device, voltDevice)
+ _ = cntlr.NewController(context.Background(), mocks.NewMockApp(gomock.NewController(t)))
+ va.PushDevFlowForVlan(tt.args.cntx, tt.args.vnet)
+ })
+ }
+}
+
+func TestVoltApplication_PushDevFlowForDevice(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ device *VoltDevice
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "device.ConfiguredVlanForDeviceFlows is ok",
+ args: args{
+ cntx: context.Background(),
+ device: &VoltDevice{
+ Name: test_device,
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ },
+ },
+ },
+ {
+ name: "device.VlanPortStatus is false",
+ args: args{
+ cntx: context.Background(),
+ device: &VoltDevice{
+ Name: test_device,
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ NniPort: "test_nni_port",
+ },
+ },
+ },
+ {
+ name: "device.VlanPortStatus is true",
+ args: args{
+ cntx: context.Background(),
+ device: &VoltDevice{
+ Name: test_device,
+ ConfiguredVlanForDeviceFlows: util.NewConcurrentMap(),
+ NniPort: "test_nni_port",
+ VlanPortStatus: sync.Map{},
+ },
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ va := &VoltApplication{}
+ switch tt.name {
+ case "device.ConfiguredVlanForDeviceFlows is ok":
+ va.VnetsByName.Store("test_vnet_name", &VoltVnet{
+ Version: "test_version",
+ })
+ tt.args.device.ConfiguredVlanForDeviceFlows.Set("0-0-0", util.NewConcurrentMap())
+ va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
+ case "device.VlanPortStatus is false":
+ va.VnetsByName.Store("test_vnet_name", &VoltVnet{
+ Version: "test_version",
+ })
+ va.PortsDisc.Store("test_nni_port", &VoltPort{
+ Name: "test_name",
+ })
+ va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
+ case "device.VlanPortStatus is true":
+ va.VnetsByName.Store("test_vnet_name", &VoltVnet{
+ Version: "test_version",
+ VnetConfig: VnetConfig{
+ SVlan: of.VlanAny,
+ },
+ })
+ va.PortsDisc.Store("test_nni_port", &VoltPort{
+ Name: "test_name",
+ })
+ tt.args.device.VlanPortStatus.Store(uint16(of.VlanAny), true)
+ va.PushDevFlowForDevice(tt.args.cntx, tt.args.device)
+ }
+ })
+ }
+}