blob: 400176ab7e47ab93635a4d3b47df84b8087de24f [file] [log] [blame]
/*
* 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 application
import (
"context"
"testing"
"voltha-go-controller/internal/pkg/intf"
"voltha-go-controller/internal/pkg/of"
"voltha-go-controller/internal/pkg/util"
"voltha-go-controller/internal/test/mocks"
"github.com/golang/mock/gomock"
)
var voltPortVnet = &VoltPortVnet{
Device: "test_device",
}
var voltService = &VoltService{
Version: "test_version",
}
func TestExecuteFlowEvent(t *testing.T) {
type args struct {
cntx context.Context
vd *VoltDevice
cookie string
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
want bool
}{
{
name: "ExecuteFlowEvent_add",
args: args{
cntx: context.Background(),
vd: &VoltDevice{
SouthBoundID: "test_device_id",
FlowAddEventMap: util.NewConcurrentMap(),
},
cookie: "test_cookie",
flowStatus: intf.FlowStatus{
Device: "test_device",
FlowModType: of.CommandAdd,
},
},
},
{
name: "ExecuteFlowEvent_del",
args: args{
cntx: context.Background(),
vd: &VoltDevice{
SouthBoundID: "test_device_id",
FlowDelEventMap: util.NewConcurrentMap(),
},
cookie: "test_cookie",
flowStatus: intf.FlowStatus{
Device: "test_device",
FlowModType: of.CommandDel,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
switch tt.name {
case "ExecuteFlowEvent_add":
if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
}
case "ExecuteFlowEvent_del":
if got := ExecuteFlowEvent(tt.args.cntx, tt.args.vd, tt.args.cookie, tt.args.flowStatus); got != tt.want {
t.Errorf("ExecuteFlowEvent() = %v, want %v", got, tt.want)
}
}
})
}
}
func TestInitEventFuncMapper(t *testing.T) {
tests := []struct {
name string
}{
{
name: "InitEventFuncMapper",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
InitEventFuncMapper()
})
}
}
func TestProcessUsIgmpFlowAddEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
}{
{
name: "ProcessUsIgmpFlowAddEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
device: "test_device",
eType: EventTypeControlFlowAdded,
eventData: voltPortVnet,
},
flowStatus: intf.FlowStatus{
Device: "test_device",
Status: uint32(0),
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ProcessUsIgmpFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}
func TestProcessServiceFlowAddEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
}{
{
name: "ProcessServiceFlowAddEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
device: "test_device",
eventData: voltService,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ProcessServiceFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}
func TestProcessControlFlowAddEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
}{
{
name: "ProcessControlFlowAddEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
eventData: voltPortVnet,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ProcessControlFlowAddEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}
func TestProcessServiceFlowDelEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
}{
{
name: "ProcessServiceFlowDelEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
eventData: voltService,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
db = dbintf
dbintf.EXPECT().PutService(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
ProcessServiceFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}
func TestProcessControlFlowDelEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
tests := []struct {
name string
args args
}{
{
name: "ProcessControlFlowDelEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
eventData: voltPortVnet,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
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).Times(1)
ProcessControlFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}
func TestProcessMcastFlowDelEvent(t *testing.T) {
type args struct {
cntx context.Context
event *FlowEvent
flowStatus intf.FlowStatus
}
mvlanProfile := &MvlanProfile{
Version: "test_version",
}
tests := []struct {
name string
args args
}{
{
name: "ProcessMcastFlowDelEvent",
args: args{
cntx: context.Background(),
event: &FlowEvent{
eventData: mvlanProfile,
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
dbintf := mocks.NewMockDBIntf(gomock.NewController(t))
db = dbintf
dbintf.EXPECT().PutMvlan(gomock.Any(), gomock.Any(), gomock.Any()).Return(nil).Times(1)
ProcessMcastFlowDelEvent(tt.args.cntx, tt.args.event, tt.args.flowStatus)
})
}
}