blob: dfb17f6d18e75b560e9e70c29b8d208ed549e1c1 [file] [log] [blame]
vinokuma04dc9f82023-07-31 15:47:49 +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 controller
17
18import (
19 "context"
20 "testing"
21 "voltha-go-controller/internal/test/mocks"
22
23 "github.com/golang/mock/gomock"
Akash Sonid36d23b2023-08-18 12:51:40 +053024 "github.com/stretchr/testify/assert"
vinokuma04dc9f82023-07-31 15:47:49 +053025)
26
27func TestPendingProfilesTask_Start(t *testing.T) {
28 type args struct {
29 ctx context.Context
30 taskID uint8
31 }
32 tests := []struct {
33 name string
34 args args
35 wantErr bool
36 }{
37 {
38 name: "PendingProfilesTask_Start",
39 args: args{
40 ctx: context.Background(),
41 taskID: uint8(1),
42 },
43 },
44 }
45 for _, tt := range tests {
46 t.Run(tt.name, func(t *testing.T) {
47 ppt := &PendingProfilesTask{
48 device: &Device{
49 ID: "test_device",
50 },
51 }
52 appMock := mocks.NewMockApp(gomock.NewController(t))
53 _ = NewController(context.Background(), appMock)
54 appMock.EXPECT().SetRebootFlag(gomock.Any()).AnyTimes()
55 appMock.EXPECT().TriggerPendingProfileDeleteReq(gomock.Any(), gomock.Any()).AnyTimes()
56 appMock.EXPECT().TriggerPendingMigrateServicesReq(gomock.Any(), gomock.Any()).AnyTimes()
57 appMock.EXPECT().UpdateMvlanProfilesForDevice(gomock.Any(), gomock.Any()).AnyTimes()
58 if err := ppt.Start(tt.args.ctx, tt.args.taskID); (err != nil) != tt.wantErr {
59 t.Errorf("PendingProfilesTask.Start() error = %v, wantErr %v", err, tt.wantErr)
60 }
61 })
62 }
63}
Akash Sonid36d23b2023-08-18 12:51:40 +053064
65func TestNewPendingProfilesTask(t *testing.T) {
66 type args struct {
67 device *Device
68 }
69 tests := []struct {
70 name string
71 args args
72 want *PendingProfilesTask
73 }{
74 {
75 name: "NewPendingProfilesTask",
76 args: args{
77 device: &Device{
78 ctx: context.Background(),
79 },
80 },
81 },
82 }
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 got := NewPendingProfilesTask(tt.args.device)
86 assert.NotNil(t, got)
87 })
88 }
89}
90
91func TestPendingProfilesTask_Name(t *testing.T) {
92 tests := []struct {
93 name string
94 want string
95 }{
96 {
97 name: "PendingProfilesTask_Name",
98 want: "Pending Profiles Task",
99 },
100 }
101 for _, tt := range tests {
102 t.Run(tt.name, func(t *testing.T) {
103 ppt := &PendingProfilesTask{}
104 if got := ppt.Name(); got != tt.want {
105 t.Errorf("PendingProfilesTask.Name() = %v, want %v", got, tt.want)
106 }
107 })
108 }
109}
110
111func TestPendingProfilesTask_TaskID(t *testing.T) {
112 tests := []struct {
113 name string
114 want uint8
115 }{
116 {
117 name: "PendingProfilesTask_TaskID",
118 },
119 }
120 for _, tt := range tests {
121 t.Run(tt.name, func(t *testing.T) {
122 ppt := &PendingProfilesTask{}
123 if got := ppt.TaskID(); got != tt.want {
124 t.Errorf("PendingProfilesTask.TaskID() = %v, want %v", got, tt.want)
125 }
126 })
127 }
128}
129
130func TestPendingProfilesTask_Timestamp(t *testing.T) {
131 tests := []struct {
132 name string
133 want string
134 }{
135 {
136 name: "PendingProfilesTask_Timestamp",
137 },
138 }
139 for _, tt := range tests {
140 t.Run(tt.name, func(t *testing.T) {
141 ppt := &PendingProfilesTask{}
142 if got := ppt.Timestamp(); got != tt.want {
143 t.Errorf("PendingProfilesTask.Timestamp() = %v, want %v", got, tt.want)
144 }
145 })
146 }
147}
148
149func TestPendingProfilesTask_Stop(t *testing.T) {
150 tests := []struct {
151 name string
152 }{
153 {
154 name: "PendingProfilesTask_Stop",
155 },
156 }
157 for _, tt := range tests {
158 t.Run(tt.name, func(t *testing.T) {
159 ppt := &PendingProfilesTask{}
160 ppt.Stop()
161 })
162 }
163}