vgc UTs part 4

Change-Id: I0e78854fefb8f0ad270a84bc88982f859a0d5995
diff --git a/internal/pkg/controller/addflows_test.go b/internal/pkg/controller/addflows_test.go
index d1e86ec..aee998f 100644
--- a/internal/pkg/controller/addflows_test.go
+++ b/internal/pkg/controller/addflows_test.go
@@ -16,8 +16,13 @@
 package controller
 
 import (
+	"context"
+	"reflect"
 	"testing"
 	"voltha-go-controller/internal/pkg/of"
+	"voltha-go-controller/internal/test/mocks"
+
+	"github.com/golang/mock/gomock"
 )
 
 func Test_isFlowOperSuccess(t *testing.T) {
@@ -47,3 +52,181 @@
 		})
 	}
 }
+
+func TestAddFlowsTask_Start(t *testing.T) {
+	type args struct {
+		ctx    context.Context
+		taskID uint8
+	}
+	tests := []struct {
+		name    string
+		args    args
+		wantErr bool
+	}{
+		{
+			name: "AddFlowsTask_Start",
+			args: args{
+				ctx:    context.Background(),
+				taskID: 0,
+			},
+			wantErr: false,
+		},
+		{
+			name: "DeleteFlowsTask_Start",
+			args: args{
+				ctx:    context.Background(),
+				taskID: 0,
+			},
+			wantErr: false,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			switch tt.name {
+			case "AddFlowsTask_Start":
+				subFlows := map[uint64]*of.VoltSubFlow{}
+				vltSubFlow := &of.VoltSubFlow{
+					Priority: 100,
+					Cookie:   103112802816,
+					State:    of.FlowAddSuccess,
+					Match: of.Match{
+						InPort:     1573376,
+						MatchVlan:  4096,
+						L4Protocol: 255,
+					},
+					Action: of.Action{
+						Metadata:    279189651712,
+						GoToTableID: 1,
+						MeterID:     1,
+						SetVlan:     4097,
+						Pcp:         8,
+						Output:      4,
+					},
+				}
+				subFlows[0] = vltSubFlow
+				portsByID := map[uint32]*DevicePort{}
+				portsByID[256] = &DevicePort{
+					Name: "SDX6320031",
+					ID:   256,
+				}
+				device := &Device{
+					flows:     subFlows,
+					PortsByID: portsByID,
+				}
+				flow := &of.VoltFlow{
+					SubFlows: subFlows,
+					PortName: "SDX6320031-1",
+					PortID:   256,
+					Command:  0,
+				}
+				aft := &AddFlowsTask{
+					flow:   flow,
+					device: device,
+				}
+				dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+				db = dbintf
+				dbintf.EXPECT().PutFlow(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+				if err := aft.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+					t.Errorf("AddFlowsTask.Start() error = %v, wantErr %v", err, tt.wantErr)
+				}
+			case "DeleteFlowsTask_Start":
+				subFlows := map[uint64]*of.VoltSubFlow{}
+				vltSubFlow := &of.VoltSubFlow{
+					Priority: 100,
+					Cookie:   103112802816,
+					State:    of.FlowAddSuccess,
+					Match: of.Match{
+						InPort:     1573376,
+						MatchVlan:  4096,
+						L4Protocol: 255,
+					},
+					Action: of.Action{
+						Metadata:    279189651712,
+						GoToTableID: 1,
+						MeterID:     1,
+						SetVlan:     4097,
+						Pcp:         8,
+						Output:      4,
+					},
+				}
+				subFlows[0] = vltSubFlow
+				portsByID := map[uint32]*DevicePort{}
+				portsByID[256] = &DevicePort{
+					Name: "SDX6320031",
+					ID:   256,
+				}
+				device := &Device{
+					flows:     subFlows,
+					PortsByID: portsByID,
+				}
+				flow := &of.VoltFlow{
+					SubFlows: subFlows,
+					PortName: "SDX6320031-1",
+					PortID:   256,
+					Command:  1,
+				}
+				aft := &AddFlowsTask{
+					flow:   flow,
+					device: device,
+				}
+				appMock := mocks.NewMockApp(gomock.NewController(t))
+				NewController(ctx, appMock)
+				appMock.EXPECT().ProcessFlowModResultIndication(gomock.Any(), gomock.Any()).AnyTimes()
+				dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+				db = dbintf
+				dbintf.EXPECT().DelFlow(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+				if err := aft.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+					t.Errorf("AddFlowsTask.Start() error = %v, wantErr %v", err, tt.wantErr)
+				}
+			}
+		})
+	}
+}
+
+func TestNewAddFlowsTask(t *testing.T) {
+	type args struct {
+		ctx    context.Context
+		flow   *of.VoltFlow
+		device *Device
+	}
+	flow := &of.VoltFlow{
+		PortName: "SDX6320031-1",
+		PortID:   256,
+		Command:  0,
+	}
+	portsByID := map[uint32]*DevicePort{}
+	portsByID[256] = &DevicePort{
+		Name: "SDX6320031",
+		ID:   256,
+	}
+	device := &Device{
+		PortsByID: portsByID,
+	}
+
+	tests := []struct {
+		name string
+		args args
+		want *AddFlowsTask
+	}{
+		{
+			name: "NewAddFlowsTask",
+			args: args{
+				ctx:    context.Background(),
+				flow:   flow,
+				device: device,
+			},
+			want: &AddFlowsTask{
+				ctx:    context.Background(),
+				flow:   flow,
+				device: device,
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			if got := NewAddFlowsTask(tt.args.ctx, tt.args.flow, tt.args.device); reflect.DeepEqual(got, tt.want) {
+				t.Errorf("NewAddFlowsTask() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
diff --git a/internal/pkg/controller/auditdevice_test.go b/internal/pkg/controller/auditdevice_test.go
new file mode 100644
index 0000000..b2a76ea
--- /dev/null
+++ b/internal/pkg/controller/auditdevice_test.go
@@ -0,0 +1,163 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package controller
+
+import (
+	"context"
+	"testing"
+	"voltha-go-controller/internal/pkg/holder"
+	"voltha-go-controller/internal/pkg/of"
+	"voltha-go-controller/internal/test/mocks"
+
+	"github.com/golang/mock/gomock"
+	"github.com/opencord/voltha-protos/v5/go/openflow_13"
+	"github.com/opencord/voltha-protos/v5/go/voltha"
+)
+
+func TestAuditDevice_DelExcessPorts(t *testing.T) {
+	type args struct {
+		cntx context.Context
+		eps  []uint32
+	}
+	subFlows := map[uint64]*of.VoltSubFlow{}
+	vltSubFlow := &of.VoltSubFlow{
+		Priority: 100,
+		Cookie:   103112802816,
+		State:    of.FlowAddSuccess,
+		Match: of.Match{
+			InPort:     1573376,
+			MatchVlan:  4096,
+			L4Protocol: 255,
+		},
+		Action: of.Action{
+			Metadata:    279189651712,
+			GoToTableID: 1,
+			MeterID:     1,
+			SetVlan:     4097,
+			Pcp:         8,
+			Output:      4,
+		},
+	}
+	subFlows[0] = vltSubFlow
+	portsByID := map[uint32]*DevicePort{}
+	portsByID[256] = &DevicePort{
+		Name:  "SDX6320031",
+		ID:    256,
+		State: PortStateUp,
+	}
+	eps := []uint32{256}
+	device := &Device{
+		flows:     subFlows,
+		PortsByID: portsByID,
+		ID:        "SDX6320031",
+	}
+	tests := []struct {
+		name string
+		args args
+	}{
+		{
+			name: "AddFlowsTask_Start",
+			args: args{
+				cntx: context.Background(),
+				eps:  eps,
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			ad := &AuditDevice{
+				device: device,
+			}
+			appMock := mocks.NewMockApp(gomock.NewController(t))
+			NewController(ctx, appMock)
+			appMock.EXPECT().PortDownInd(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+			appMock.EXPECT().PortDelInd(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+			dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+			db = dbintf
+			dbintf.EXPECT().DelPort(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+			ad.DelExcessPorts(tt.args.cntx, tt.args.eps)
+		})
+	}
+}
+
+func TestAuditDevice_Start(t *testing.T) {
+	type args struct {
+		ctx    context.Context
+		taskID uint8
+	}
+	volthaClientMock := mocks.NewMockVolthaServiceClient(gomock.NewController(t))
+	volthaServiceClientHolder := &holder.VolthaServiceClientHolder{
+		VolthaSvcClient: volthaClientMock,
+	}
+	portsByID := map[uint32]*DevicePort{}
+	portsByID[16777216] = &DevicePort{
+		Name:  "SDX6320031",
+		ID:    16777216,
+		State: PortStateUp,
+	}
+	device := &Device{
+		ID:            "SDX6320031",
+		vclientHolder: volthaServiceClientHolder,
+		PortsByID:     portsByID,
+	}
+	items := []*voltha.LogicalPort{}
+	item := &voltha.LogicalPort{
+		Id:           "SDX6320031-1",
+		DeviceId:     "SDX6320031",
+		DevicePortNo: 16777216,
+		OfpPort: &openflow_13.OfpPort{
+			PortNo: 16777216,
+			Name:   "SDX6320031-1",
+		},
+	}
+	items = append(items, item)
+
+	ofpps := &voltha.LogicalPorts{
+		Items: items,
+	}
+	tests := []struct {
+		name    string
+		args    args
+		wantErr bool
+	}{
+		{
+			name: "AddFlowsTask_Start",
+			args: args{
+				ctx:    context.Background(),
+				taskID: 0,
+			},
+			wantErr: false,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			ad := &AuditDevice{
+				device: device,
+			}
+			volthaClientMock.EXPECT().ListLogicalDevicePorts(gomock.Any(), gomock.Any(), gomock.Any()).Return(ofpps, nil).AnyTimes()
+			appMock := mocks.NewMockApp(gomock.NewController(t))
+			NewController(ctx, appMock)
+			appMock.EXPECT().SetRebootFlag(gomock.Any()).AnyTimes()
+			appMock.EXPECT().PortDownInd(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes()
+			dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
+			db = dbintf
+			dbintf.EXPECT().PutPort(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).AnyTimes()
+			if err := ad.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+				t.Errorf("AuditDevice.Start() error = %v, wantErr %v", err, tt.wantErr)
+			}
+		})
+	}
+}
diff --git a/internal/pkg/controller/pendingprofiles_test.go b/internal/pkg/controller/pendingprofiles_test.go
new file mode 100644
index 0000000..fe0639c
--- /dev/null
+++ b/internal/pkg/controller/pendingprofiles_test.go
@@ -0,0 +1,62 @@
+/*
+* Copyright 2022-present Open Networking Foundation
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+ */
+
+package controller
+
+import (
+	"context"
+	"testing"
+	"voltha-go-controller/internal/test/mocks"
+
+	"github.com/golang/mock/gomock"
+)
+
+func TestPendingProfilesTask_Start(t *testing.T) {
+	type args struct {
+		ctx    context.Context
+		taskID uint8
+	}
+	tests := []struct {
+		name    string
+		args    args
+		wantErr bool
+	}{
+		{
+			name: "PendingProfilesTask_Start",
+			args: args{
+				ctx:    context.Background(),
+				taskID: uint8(1),
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			ppt := &PendingProfilesTask{
+				device: &Device{
+					ID: "test_device",
+				},
+			}
+			appMock := mocks.NewMockApp(gomock.NewController(t))
+			_ = NewController(context.Background(), appMock)
+			appMock.EXPECT().SetRebootFlag(gomock.Any()).AnyTimes()
+			appMock.EXPECT().TriggerPendingProfileDeleteReq(gomock.Any(), gomock.Any()).AnyTimes()
+			appMock.EXPECT().TriggerPendingMigrateServicesReq(gomock.Any(), gomock.Any()).AnyTimes()
+			appMock.EXPECT().UpdateMvlanProfilesForDevice(gomock.Any(), gomock.Any()).AnyTimes()
+			if err := ppt.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
+				t.Errorf("PendingProfilesTask.Start() error = %v, wantErr %v", err, tt.wantErr)
+			}
+		})
+	}
+}