blob: 8a71b29601f72f33fd3256551901a0a466affaa0 [file] [log] [blame]
Akash Soni230e6212023-10-16 10:46:07 +05301/*
2* Copyright 2022-present Open Networking Foundation
3* Licensed under the Apache License, Version 2.0 (the "License");
4* you may not use this file except in compliance with the License.
5* You may obtain a copy of the License at
6*
7* http://www.apache.org/licenses/LICENSE-2.0
8*
9* Unless required by applicable law or agreed to in writing, software
10* distributed under the License is distributed on an "AS IS" BASIS,
11* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12* See the License for the specific language governing permissions and
13* limitations under the License.
14 */
15
16package application
17
18import (
19 "context"
20 "testing"
21 "voltha-go-controller/internal/pkg/of"
22
23 "github.com/google/gopacket"
24 "github.com/stretchr/testify/assert"
25)
26
27func TestTickTask_Name(t *testing.T) {
28 tt := &TickTask{}
29 got := tt.Name()
30 assert.NotNil(t, got)
31 got1 := tt.TaskID()
32 assert.NotNil(t, got1)
33 got2 := tt.Timestamp()
34 assert.NotNil(t, got2)
35 ipk := IgmpPacketTask{}
36 got3 := ipk.Name()
37 assert.NotNil(t, got3)
38 got4 := ipk.TaskID()
39 assert.NotNil(t, got4)
40 got5 := ipk.Timestamp()
41 assert.NotNil(t, got5)
42 mt := &UpdateMvlanTask{}
43 got6 := mt.Name()
44 assert.NotNil(t, got6)
45 got7 := mt.TaskID()
46 assert.NotNil(t, got7)
47 got8 := mt.Timestamp()
48 assert.NotNil(t, got8)
49 got9 := NewTickTask()
50 assert.NotNil(t, got9)
51}
52
53func TestTickTask_Start(t *testing.T) {
54 type args struct {
55 ctx context.Context
56 taskID uint8
57 }
58 tests := []struct {
59 name string
60 args args
61 wantErr bool
62 }{
63 {
64 name: "TickTask_Start",
65 args: args{
66 ctx: context.Background(),
67 },
68 wantErr: false,
69 },
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 tt1 := &TickTask{}
74 if err := tt1.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
75 t.Errorf("TickTask.Start() error = %v, wantErr %v", err, tt.wantErr)
76 }
77 })
78 }
79}
80
81func TestNewIgmpPacketTask(t *testing.T) {
82 type args struct {
83 device string
84 port string
85 pkt gopacket.Packet
86 }
87 tests := []struct {
88 name string
89 args args
90 want *IgmpPacketTask
91 }{
92 {
93 name: "NewIgmpPacketTask",
94 args: args{
95 device: "SDX6320031",
96 port: "16777472",
97 },
98 want: &IgmpPacketTask{},
99 },
100 }
101 for _, tt := range tests {
102 t.Run(tt.name, func(t *testing.T) {
103 got := NewIgmpPacketTask(tt.args.device, tt.args.port, tt.args.pkt)
104 assert.NotNil(t, got)
105 })
106 }
107}
108
109func TestNewUpdateMvlanTask(t *testing.T) {
110 type args struct {
111 mvp *MvlanProfile
112 deviceID string
113 }
114 tests := []struct {
115 name string
116 args args
117 want *UpdateMvlanTask
118 }{
119 {
120 name: "NewUpdateMvlanTask",
121 args: args{
122 mvp: &MvlanProfile{},
123 deviceID: "SDX6320031",
124 },
125 want: &UpdateMvlanTask{},
126 },
127 }
128 for _, tt := range tests {
129 t.Run(tt.name, func(t *testing.T) {
130 got := NewUpdateMvlanTask(tt.args.mvp, tt.args.deviceID)
131 assert.NotNil(t, got)
132 })
133 }
134}
135
136func TestUpdateMvlanTask_Start(t *testing.T) {
137 type args struct {
138 ctx context.Context
139 taskID uint8
140 }
141 tests := []struct {
142 name string
143 args args
144 wantErr bool
145 }{
146 {
147 name: "UpdateMvlanTask_Start",
148 args: args{
149 ctx: context.Background(),
150 taskID: uint8(123),
151 },
152 },
153 }
154 for _, tt := range tests {
155 t.Run(tt.name, func(t *testing.T) {
156 mt := &UpdateMvlanTask{
157 DeviceID: "SDX6320031",
158 mvp: &MvlanProfile{
159 Mvlan: of.VlanAny,
160 },
161 }
162 if err := mt.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
163 t.Errorf("UpdateMvlanTask.Start() error = %v, wantErr %v", err, tt.wantErr)
164 }
165 })
166 }
167}