UT-Part 6 with overall coverage upto 45%
Change-Id: I4960bae8429ae34d88a2f98f288f72d582f9e788
diff --git a/internal/pkg/controller/controller.go b/internal/pkg/controller/controller.go
index 9ccb21d..7e1a726 100644
--- a/internal/pkg/controller/controller.go
+++ b/internal/pkg/controller/controller.go
@@ -48,6 +48,19 @@
var db database.DBIntf
+type VoltControllerInterface interface {
+ GetDevice(id string) (*Device, error)
+ GetAllPendingFlows() ([]*of.VoltSubFlow, error)
+ GetAllFlows() ([]*of.VoltSubFlow, error)
+ GetFlows(deviceID string) ([]*of.VoltSubFlow, error)
+ GetFlow(deviceID string, cookie uint64) (*of.VoltSubFlow, error)
+ GetGroups(cntx context.Context, id uint32) (*of.Group, error)
+ GetGroupList() ([]*of.Group, error)
+ GetMeterInfo(cntx context.Context, id uint32) (map[string]*of.Meter, error)
+ GetAllMeterInfo() (map[string][]*of.Meter, error)
+ GetTaskList(device string) []tasks.Task
+}
+
// VoltController structure
type VoltController struct {
ctx context.Context
@@ -517,7 +530,7 @@
return d.GetTaskList()
}
-// AddBlockedDevices to add devices to blocked devices list
+// AddBlockedDevices to add Devices to blocked Devices list
func (v *VoltController) AddBlockedDevices(deviceSerialNumber string) {
v.BlockedDeviceList.Set(deviceSerialNumber, deviceSerialNumber)
}
diff --git a/internal/pkg/controller/controller_test.go b/internal/pkg/controller/controller_test.go
index 2c4b993..235bffe 100644
--- a/internal/pkg/controller/controller_test.go
+++ b/internal/pkg/controller/controller_test.go
@@ -23,6 +23,7 @@
"voltha-go-controller/internal/pkg/intf"
"voltha-go-controller/internal/pkg/of"
"voltha-go-controller/internal/pkg/tasks"
+ "voltha-go-controller/internal/pkg/util"
"voltha-go-controller/internal/pkg/vpagent"
"voltha-go-controller/internal/test/mocks"
@@ -946,7 +947,7 @@
type args struct {
device string
}
- rebootInProgressDevices := map[string]string{}
+ rebootInProgressdevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
@@ -976,7 +977,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressDevices,
+ rebootInProgressDevices: rebootInProgressdevices,
devices: dev,
}
switch tt.name {
@@ -997,12 +998,12 @@
type args struct {
device string
}
- rebootInProgressDevices := map[string]string{}
+ rebootInProgressdevices := map[string]string{}
device := &Device{
ctx: context.Background(),
ID: "SDX6320031",
}
- rebootInProgressDevices["SDX6320031"] = "done"
+ rebootInProgressdevices["SDX6320031"] = "done"
dev := map[string]*Device{}
dev["SDX6320031"] = device
tests := []struct {
@@ -1021,7 +1022,7 @@
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &VoltController{
- rebootInProgressDevices: rebootInProgressDevices,
+ rebootInProgressDevices: rebootInProgressdevices,
devices: dev,
}
if got := v.ReSetRebootInProgressForDevice(tt.args.device); got != tt.want {
@@ -1030,3 +1031,201 @@
})
}
}
+
+func TestVoltController_IsBlockedDevice(t *testing.T) {
+ type args struct {
+ deviceserialNumber string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "IsBlockedDevice",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ {
+ name: "deviceserialNumber",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ {
+ name: "AddBlockeddevices",
+ args: args{
+ deviceserialNumber: "SDX6320031",
+ },
+ want: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{
+ BlockedDeviceList: util.NewConcurrentMap(),
+ }
+ switch tt.name {
+ case "IsBlockedDevice":
+ if got := v.IsBlockedDevice(tt.args.deviceserialNumber); got != tt.want {
+ t.Errorf("VoltController.IsBlockedDevice() = %v, want %v", got, tt.want)
+ }
+ case "deviceserialNumber":
+ v.DelBlockedDevices(tt.args.deviceserialNumber)
+ case "AddBlockeddevices":
+ v.AddBlockedDevices(tt.args.deviceserialNumber)
+ }
+ })
+ }
+}
+
+func TestVoltController_SetDeviceTableSyncDuration(t *testing.T) {
+ type args struct {
+ duration int
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "SetDeviceTableSyncDuration",
+ args: args{
+ duration: 1,
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{}
+ switch tt.name {
+ case "SetDeviceTableSyncDuration":
+ v.SetDeviceTableSyncDuration(tt.args.duration)
+ v.GetDeviceTableSyncDuration()
+ }
+ })
+ }
+}
+
+func TestVoltController_IsRebootInProgressForDevice(t *testing.T) {
+ type args struct {
+ device string
+ }
+ tests := []struct {
+ name string
+ args args
+ want bool
+ }{
+ {
+ name: "SetDeviceTableSyncDuration",
+ args: args{
+ device: "SDX6320031",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ v := &VoltController{}
+ if got := v.IsRebootInProgressForDevice(tt.args.device); got != tt.want {
+ t.Errorf("VoltController.IsRebootInProgressForDevice() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
+
+func TestVoltController_GroupUpdate(t *testing.T) {
+ type args struct {
+ port string
+ device string
+ group *of.Group
+ }
+ portsByName := map[string]*DevicePort{}
+ portsByName["SDX6320031-1"] = &DevicePort{
+ Name: "SDX6320031-1",
+ ID: 256,
+ }
+ device := &Device{
+ ctx: context.Background(),
+ ID: "SDX6320031",
+ groups: sync.Map{},
+ PortsByName: portsByName,
+ }
+ dev := map[string]*Device{}
+ dev["SDX6320031"] = device
+ grp := &of.Group{
+ Device: "SDX6320031",
+ GroupID: uint32(256),
+ State: 1,
+ SetVlan: of.VlanAny,
+ }
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutGroup(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "GroupUpdate",
+ args: args{
+ port: "SDX6320031-1",
+ device: "SDX6320031",
+ group: grp,
+ },
+ wantErr: false,
+ },
+ {
+ name: "DeviceNOtFound_Error",
+ args: args{
+ device: "SDX632003134",
+ },
+ wantErr: true,
+ },
+ {
+ name: "PortNOtFound_Error",
+ args: args{
+ device: "SDX6320031",
+ port: "SDX632003134",
+ },
+ wantErr: true,
+ },
+ {
+ name: "ContextNill_Error",
+ args: args{
+ device: "SDX6320031",
+ port: "SDX6320031-1",
+ },
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ switch tt.name {
+ case "GroupUpdate", "DeviceNOtFound_Error", "PortNOtFound_Error":
+ v := &VoltController{
+ devices: dev,
+ }
+ if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
+ t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ case "ContextNill_Error":
+ device := &Device{
+ ID: "SDX6320031",
+ groups: sync.Map{},
+ PortsByName: portsByName,
+ }
+ dev := map[string]*Device{}
+ dev["SDX6320031"] = device
+ v := &VoltController{
+ devices: dev,
+ }
+ if err := v.GroupUpdate(tt.args.port, tt.args.device, tt.args.group); (err != nil) != tt.wantErr {
+ t.Errorf("VoltController.GroupUpdate() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ }
+ })
+ }
+}
diff --git a/internal/pkg/controller/device.go b/internal/pkg/controller/device.go
index 57474a0..193c3fb 100644
--- a/internal/pkg/controller/device.go
+++ b/internal/pkg/controller/device.go
@@ -119,6 +119,10 @@
DeviceStateDELETED DeviceState = "DELETED"
)
+type DeviceInterface interface {
+ SetFlowHash(cntx context.Context, hash uint32)
+}
+
// Device structure
type Device struct {
ctx context.Context
diff --git a/internal/pkg/controller/device_test.go b/internal/pkg/controller/device_test.go
index 11084fd..8f35aef 100644
--- a/internal/pkg/controller/device_test.go
+++ b/internal/pkg/controller/device_test.go
@@ -209,3 +209,73 @@
})
}
}
+
+func TestDevice_PacketOutReq(t *testing.T) {
+ type args struct {
+ outport string
+ inport string
+ data []byte
+ isCustomPkt bool
+ }
+ tests := []struct {
+ name string
+ args args
+ wantErr bool
+ }{
+ {
+ name: "Device_PacketOutReq",
+ args: args{
+ outport: "test_out_port",
+ inport: "test_in_port",
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ portByName := make(map[string]*DevicePort)
+ portByName["test_in_port"] = &DevicePort{
+ Name: "test_device",
+ }
+ portByName["test_out_port"] = &DevicePort{
+ Name: "test_device",
+ }
+ packetOutChannel := make(chan *ofp.PacketOut, 2)
+
+ d := &Device{
+ packetOutChannel: packetOutChannel,
+ PortsByName: portByName,
+ }
+ if err := d.PacketOutReq(tt.args.outport, tt.args.inport, tt.args.data, tt.args.isCustomPkt); (err != nil) != tt.wantErr {
+ t.Errorf("Device.PacketOutReq() error = %v, wantErr %v", err, tt.wantErr)
+ }
+ })
+ }
+}
+
+func TestDevice_SetFlowHash(t *testing.T) {
+ type args struct {
+ cntx context.Context
+ hash uint32
+ }
+ tests := []struct {
+ name string
+ args args
+ }{
+ {
+ name: "Device_SetFlowHash",
+ args: args{
+ cntx: context.Background(),
+ hash: uint32(2),
+ },
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ d := &Device{}
+ dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+ db = dbintf
+ dbintf.EXPECT().PutFlowHash(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
+ d.SetFlowHash(tt.args.cntx, tt.args.hash)
+ })
+ }
+}