cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 17 | /* |
| 18 | This file contains unit test cases for functions in the file openolt.go. |
| 19 | This file also implements the fields struct to mock the Openolt and few utility functions. |
| 20 | */ |
| 21 | |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 22 | //Package core provides the utility for olt devices, flows and statistics |
| 23 | package core |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 24 | |
| 25 | import ( |
| 26 | "context" |
| 27 | "errors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 28 | com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common" |
| 29 | fu "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 30 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 31 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 32 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 33 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 34 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 35 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 36 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 37 | "github.com/opencord/voltha-protos/v3/go/voltha" |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 38 | "reflect" |
| 39 | "sync" |
| 40 | "testing" |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 41 | ) |
| 42 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 43 | // mocks the OpenOLT struct. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 44 | type fields struct { |
| 45 | deviceHandlers map[string]*DeviceHandler |
| 46 | coreProxy *com.CoreProxy |
| 47 | adapterProxy *com.AdapterProxy |
| 48 | eventProxy *com.EventProxy |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 49 | kafkaICProxy kafka.InterContainerProxy |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 50 | numOnus int |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame^] | 51 | KVStoreAddress string |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 52 | KVStoreType string |
| 53 | exitChannel chan int |
| 54 | lockDeviceHandlersMap sync.RWMutex |
| 55 | ctx context.Context |
| 56 | } |
| 57 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 58 | // mockOlt mocks OpenOLT struct. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 59 | func mockOlt() *fields { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 60 | dh := newMockDeviceHandler() |
| 61 | newOlt := &fields{} |
| 62 | newOlt.deviceHandlers = map[string]*DeviceHandler{} |
| 63 | newOlt.deviceHandlers[dh.device.Id] = dh |
| 64 | return newOlt |
| 65 | } |
| 66 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 67 | // testOltObject maps fields type to OpenOLt type. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 68 | func testOltObject(testOlt *fields) *OpenOLT { |
| 69 | return &OpenOLT{ |
| 70 | deviceHandlers: testOlt.deviceHandlers, |
| 71 | coreProxy: testOlt.coreProxy, |
| 72 | adapterProxy: testOlt.adapterProxy, |
| 73 | eventProxy: testOlt.eventProxy, |
| 74 | kafkaICProxy: testOlt.kafkaICProxy, |
| 75 | numOnus: testOlt.numOnus, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame^] | 76 | KVStoreAddress: testOlt.KVStoreAddress, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 77 | KVStoreType: testOlt.KVStoreType, |
| 78 | exitChannel: testOlt.exitChannel, |
| 79 | } |
| 80 | } |
| 81 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 82 | // mockDevice mocks Device. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 83 | func mockDevice() *voltha.Device { |
| 84 | device := &voltha.Device{ |
| 85 | Id: "olt", |
| 86 | Root: true, |
| 87 | ParentId: "logical_device", |
| 88 | Ports: []*voltha.Port{ |
| 89 | {PortNo: 1, Label: "pon"}, |
| 90 | {PortNo: 2, Label: "nni"}, |
| 91 | }, |
| 92 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 93 | DeviceId: "olt", |
| 94 | DeviceType: "onu", |
| 95 | ChannelId: 1, |
| 96 | ChannelGroupId: 1, |
| 97 | }, |
| 98 | ConnectStatus: 1, |
| 99 | } |
| 100 | return device |
| 101 | } |
| 102 | |
| 103 | func TestNewOpenOLT(t *testing.T) { |
| 104 | tests := []struct { |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 105 | name string |
| 106 | fields *fields |
| 107 | configFlags *config.AdapterFlags |
| 108 | want *OpenOLT |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 109 | }{ |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame^] | 110 | {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}, |
| 111 | &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}}, |
| 112 | {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}, |
| 113 | &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}}, |
| 114 | {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}, |
| 115 | &OpenOLT{numOnus: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 116 | } |
| 117 | for _, tt := range tests { |
| 118 | t.Run(tt.name, func(t *testing.T) { |
| 119 | if got := NewOpenOLT(tt.fields.ctx, tt.fields.kafkaICProxy, tt.fields.coreProxy, tt.fields.adapterProxy, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 120 | tt.fields.eventProxy, tt.configFlags); reflect.TypeOf(got) != reflect.TypeOf(tt.want) && got != nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 121 | t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want) |
| 122 | } |
| 123 | }) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func TestOpenOLT_Abandon_device(t *testing.T) { |
| 128 | type args struct { |
| 129 | device *voltha.Device |
| 130 | } |
| 131 | tests := []struct { |
| 132 | name string |
| 133 | fields *fields |
| 134 | args args |
| 135 | wantErr error |
| 136 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 137 | {"abandon_device-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 138 | {"abandon_device-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 139 | {"abandon_device-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 140 | } |
| 141 | for _, tt := range tests { |
| 142 | t.Run(tt.name, func(t *testing.T) { |
| 143 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 144 | if err := oo.Abandon_device(tt.args.device); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 145 | t.Errorf("Abandon_device() error = %v, wantErr %v", err, tt.wantErr) |
| 146 | } |
| 147 | }) |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | func TestOpenOLT_Activate_image_update(t *testing.T) { |
| 152 | type args struct { |
| 153 | device *voltha.Device |
| 154 | request *voltha.ImageDownload |
| 155 | } |
| 156 | tests := []struct { |
| 157 | name string |
| 158 | fields *fields |
| 159 | args args |
| 160 | want *voltha.ImageDownload |
| 161 | wantErr error |
| 162 | }{ |
| 163 | {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 164 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 165 | {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 166 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 167 | {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 168 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 169 | } |
| 170 | for _, tt := range tests { |
| 171 | t.Run(tt.name, func(t *testing.T) { |
| 172 | oo := testOltObject(tt.fields) |
| 173 | got, err := oo.Activate_image_update(tt.args.device, tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 174 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 175 | t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr) |
| 176 | } |
| 177 | }) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | func TestOpenOLT_Adapter_descriptor(t *testing.T) { |
| 182 | tests := []struct { |
| 183 | name string |
| 184 | fields *fields |
| 185 | wantErr error |
| 186 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 187 | {"adapter_descriptor-1", &fields{}, olterrors.ErrNotImplemented}, |
| 188 | {"adapter_descriptor-2", &fields{}, olterrors.ErrNotImplemented}, |
| 189 | {"adapter_descriptor-3", &fields{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 190 | } |
| 191 | for _, tt := range tests { |
| 192 | t.Run(tt.name, func(t *testing.T) { |
| 193 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 194 | if err := oo.Adapter_descriptor(); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 195 | t.Errorf("Adapter_descriptor() error = %v, wantErr %v", err, tt.wantErr) |
| 196 | } |
| 197 | }) |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | func TestOpenOLT_Adopt_device(t *testing.T) { |
| 202 | type args struct { |
| 203 | device *voltha.Device |
| 204 | } |
| 205 | var device = mockDevice() |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 206 | device.Id = "olt" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 207 | nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 208 | tests := []struct { |
| 209 | name string |
| 210 | fields *fields |
| 211 | args args |
| 212 | wantErr error |
| 213 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 214 | {"adopt_device-1", mockOlt(), args{}, nilDevice}, |
| 215 | {"adopt_device-2", mockOlt(), args{device}, nilDevice}, |
| 216 | {"adopt_device-3", mockOlt(), args{mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 217 | } |
| 218 | for _, tt := range tests { |
| 219 | t.Run(tt.name, func(t *testing.T) { |
| 220 | oo := testOltObject(tt.fields) |
| 221 | err := oo.Adopt_device(tt.args.device) |
| 222 | if (err != nil) && (reflect.TypeOf(err) != |
| 223 | reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) { |
| 224 | t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr) |
| 225 | } |
| 226 | if err == nil { |
| 227 | t.Log("return'd nil") |
| 228 | } |
| 229 | }) |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | func TestOpenOLT_Cancel_image_download(t *testing.T) { |
| 234 | type args struct { |
| 235 | device *voltha.Device |
| 236 | request *voltha.ImageDownload |
| 237 | } |
| 238 | tests := []struct { |
| 239 | name string |
| 240 | fields *fields |
| 241 | args args |
| 242 | want *voltha.ImageDownload |
| 243 | wantErr error |
| 244 | }{ |
| 245 | {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 246 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 247 | {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 248 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 249 | {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 250 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 251 | } |
| 252 | for _, tt := range tests { |
| 253 | t.Run(tt.name, func(t *testing.T) { |
| 254 | oo := testOltObject(tt.fields) |
| 255 | got, err := oo.Cancel_image_download(tt.args.device, tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 256 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 257 | t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr) |
| 258 | } |
| 259 | }) |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | func TestOpenOLT_Delete_device(t *testing.T) { |
| 264 | type args struct { |
| 265 | device *voltha.Device |
| 266 | } |
| 267 | tests := []struct { |
| 268 | name string |
| 269 | fields *fields |
| 270 | args args |
| 271 | wantErr error |
| 272 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 273 | {"delete_device-1", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 274 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 275 | } |
| 276 | for _, tt := range tests { |
| 277 | t.Run(tt.name, func(t *testing.T) { |
| 278 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 279 | if err := oo.Delete_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 280 | t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr) |
| 281 | } |
| 282 | }) |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func TestOpenOLT_Device_types(t *testing.T) { |
| 287 | tests := []struct { |
| 288 | name string |
| 289 | fields *fields |
| 290 | want *voltha.DeviceTypes |
| 291 | wantErr error |
| 292 | }{ |
| 293 | {"device_types-1", &fields{}, &voltha.DeviceTypes{}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 294 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 295 | {"device_types-2", &fields{}, &voltha.DeviceTypes{}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 296 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 297 | {"device_types-3", &fields{}, &voltha.DeviceTypes{}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 298 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 299 | } |
| 300 | for _, tt := range tests { |
| 301 | t.Run(tt.name, func(t *testing.T) { |
| 302 | oo := testOltObject(tt.fields) |
| 303 | got, err := oo.Device_types() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 304 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 305 | t.Errorf("Device_types() error = %v, wantErr %v", err, tt.wantErr) |
| 306 | } |
| 307 | }) |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func TestOpenOLT_Disable_device(t *testing.T) { |
| 312 | type args struct { |
| 313 | device *voltha.Device |
| 314 | } |
| 315 | tests := []struct { |
| 316 | name string |
| 317 | fields *fields |
| 318 | args args |
| 319 | wantErr error |
| 320 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 321 | {"disable_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 322 | {"disable_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 323 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 324 | } |
| 325 | for _, tt := range tests { |
| 326 | t.Run(tt.name, func(t *testing.T) { |
| 327 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 328 | if err := oo.Disable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 329 | t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr) |
| 330 | } |
| 331 | }) |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | func TestOpenOLT_Download_image(t *testing.T) { |
| 336 | type args struct { |
| 337 | device *voltha.Device |
| 338 | request *voltha.ImageDownload |
| 339 | } |
| 340 | tests := []struct { |
| 341 | name string |
| 342 | fields *fields |
| 343 | args args |
| 344 | want *voltha.ImageDownload |
| 345 | wantErr error |
| 346 | }{ |
| 347 | {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 348 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 349 | {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 350 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 351 | {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 352 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 353 | } |
| 354 | for _, tt := range tests { |
| 355 | t.Run(tt.name, func(t *testing.T) { |
| 356 | oo := testOltObject(tt.fields) |
| 357 | got, err := oo.Download_image(tt.args.device, tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 358 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 359 | t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr) |
| 360 | } |
| 361 | }) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | func TestOpenOLT_Get_device_details(t *testing.T) { |
| 366 | type args struct { |
| 367 | device *voltha.Device |
| 368 | } |
| 369 | tests := []struct { |
| 370 | name string |
| 371 | fields *fields |
| 372 | args args |
| 373 | wantErr error |
| 374 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 375 | {"get_device_details-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 376 | {"get_device_details-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 377 | {"get_device_details-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 378 | } |
| 379 | for _, tt := range tests { |
| 380 | t.Run(tt.name, func(t *testing.T) { |
| 381 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 382 | if err := oo.Get_device_details(tt.args.device); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 383 | t.Errorf("Get_device_details() error = %v, wantErr %v", err, tt.wantErr) |
| 384 | } |
| 385 | }) |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | func TestOpenOLT_Get_image_download_status(t *testing.T) { |
| 390 | type args struct { |
| 391 | device *voltha.Device |
| 392 | request *voltha.ImageDownload |
| 393 | } |
| 394 | tests := []struct { |
| 395 | name string |
| 396 | fields *fields |
| 397 | args args |
| 398 | want *voltha.ImageDownload |
| 399 | wantErr error |
| 400 | }{ |
| 401 | {"get_image_download_status-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 402 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 403 | {"get_image_download_status-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 404 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 405 | {"get_image_download_status-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123DFG"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 406 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 407 | } |
| 408 | for _, tt := range tests { |
| 409 | t.Run(tt.name, func(t *testing.T) { |
| 410 | oo := testOltObject(tt.fields) |
| 411 | got, err := oo.Get_image_download_status(tt.args.device, tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 412 | if err != tt.wantErr && got == nil { |
| 413 | t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v", |
| 414 | got, tt.want, err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 415 | } |
| 416 | }) |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | func TestOpenOLT_Get_ofp_device_info(t *testing.T) { |
| 421 | type args struct { |
| 422 | device *voltha.Device |
| 423 | } |
| 424 | tests := []struct { |
| 425 | name string |
| 426 | fields *fields |
| 427 | args args |
| 428 | want *ic.SwitchCapability |
| 429 | wantErr error |
| 430 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 431 | {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ic.SwitchCapability{ |
| 432 | Desc: &openflow_13.OfpDesc{ |
| 433 | MfrDesc: "VOLTHA Project", |
| 434 | HwDesc: "open_pon", |
| 435 | SwDesc: "open_pon", |
| 436 | }, |
| 437 | SwitchFeatures: &openflow_13.OfpSwitchFeatures{ |
| 438 | NBuffers: uint32(256), |
| 439 | NTables: uint32(2), |
| 440 | Capabilities: uint32(15), |
| 441 | }, |
| 442 | }, nil}, |
| 443 | {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 444 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 445 | } |
| 446 | for _, tt := range tests { |
| 447 | t.Run(tt.name, func(t *testing.T) { |
| 448 | oo := testOltObject(tt.fields) |
| 449 | got, err := oo.Get_ofp_device_info(tt.args.device) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 450 | if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) { |
| 451 | t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v", |
| 452 | got, tt.want, err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 453 | } |
| 454 | }) |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | func TestOpenOLT_Get_ofp_port_info(t *testing.T) { |
| 459 | type args struct { |
| 460 | device *voltha.Device |
| 461 | portNo int64 |
| 462 | } |
| 463 | tests := []struct { |
| 464 | name string |
| 465 | fields *fields |
| 466 | args args |
| 467 | want *ic.PortCapability |
| 468 | wantErr error |
| 469 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 470 | {"get_ofp_port_info-1", mockOlt(), args{mockDevice(), 1}, &ic.PortCapability{ |
| 471 | Port: &voltha.LogicalPort{ |
| 472 | DeviceId: "olt", |
| 473 | DevicePortNo: uint32(1), |
| 474 | OfpPort: &openflow_13.OfpPort{ |
| 475 | HwAddr: []uint32{1, 2, 3, 4, 5, 6}, |
| 476 | State: uint32(4), |
| 477 | Curr: uint32(4128), |
| 478 | Advertised: uint32(4128), |
| 479 | Peer: uint32(4128), |
| 480 | CurrSpeed: uint32(32), |
| 481 | MaxSpeed: uint32(32), |
| 482 | }, |
| 483 | }, |
| 484 | }, nil}, |
| 485 | {"get_ofp_port_info-2", &fields{}, args{mockDevice(), 1}, nil, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 486 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 487 | } |
| 488 | for _, tt := range tests { |
| 489 | t.Run(tt.name, func(t *testing.T) { |
| 490 | oo := testOltObject(tt.fields) |
| 491 | got, err := oo.Get_ofp_port_info(tt.args.device, tt.args.portNo) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 492 | if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) { |
| 493 | t.Errorf("Get_ofp_port_info() got = %v want = %v error = %v, wantErr = %v", |
| 494 | got, tt.want, err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 495 | } |
| 496 | }) |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | func TestOpenOLT_Health(t *testing.T) { |
| 501 | tests := []struct { |
| 502 | name string |
| 503 | fields *fields |
| 504 | want *voltha.HealthStatus |
| 505 | wantErr error |
| 506 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 507 | {"health-1", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented}, |
| 508 | {"health-2", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented}, |
| 509 | {"health-3", &fields{}, &voltha.HealthStatus{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 510 | } |
| 511 | for _, tt := range tests { |
| 512 | t.Run(tt.name, func(t *testing.T) { |
| 513 | oo := testOltObject(tt.fields) |
| 514 | got, err := oo.Health() |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 515 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 516 | t.Errorf("Get_ofp_port_info() error = %v, wantErr %v", err, tt.wantErr) |
| 517 | } |
| 518 | }) |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | func TestOpenOLT_Process_inter_adapter_message(t *testing.T) { |
| 523 | type args struct { |
| 524 | msg *ic.InterAdapterMessage |
| 525 | } |
| 526 | var message1 = args{ |
| 527 | msg: &ic.InterAdapterMessage{ |
| 528 | Header: &ic.InterAdapterHeader{ |
| 529 | Id: "olt", |
| 530 | ProxyDeviceId: "", |
| 531 | ToDeviceId: "onu1", |
| 532 | }, |
| 533 | }, |
| 534 | } |
| 535 | var message2 = args{ |
| 536 | msg: &ic.InterAdapterMessage{ |
| 537 | Header: &ic.InterAdapterHeader{ |
| 538 | Id: "olt", |
| 539 | ProxyDeviceId: "olt", |
| 540 | ToDeviceId: "olt", |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 541 | Type: ic.InterAdapterMessageType_OMCI_REQUEST, |
| 542 | }, |
| 543 | }, |
| 544 | } |
| 545 | var message3 = args{ |
| 546 | msg: &ic.InterAdapterMessage{ |
| 547 | Header: &ic.InterAdapterHeader{ |
| 548 | Id: "olt", |
| 549 | ProxyDeviceId: "olt", |
| 550 | ToDeviceId: "olt", |
| 551 | Type: ic.InterAdapterMessageType_FLOW_REQUEST, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 552 | }, |
| 553 | }, |
| 554 | } |
| 555 | tests := []struct { |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 556 | name string |
| 557 | fields *fields |
| 558 | args args |
| 559 | wantErrType reflect.Type |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 560 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 561 | {"process_inter_adaptor_messgae-1", mockOlt(), message1, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 562 | reflect.TypeOf(&olterrors.ErrNotFound{})}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 563 | {"process_inter_adaptor_messgae-2", mockOlt(), message2, |
Girish Kumar | f26e488 | 2020-03-05 06:49:10 +0000 | [diff] [blame] | 564 | reflect.TypeOf(&olterrors.ErrAdapter{})}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 565 | {"process_inter_adaptor_messgae-3", mockOlt(), message3, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 566 | reflect.TypeOf(&olterrors.ErrInvalidValue{})}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 567 | } |
| 568 | for _, tt := range tests { |
| 569 | t.Run(tt.name, func(t *testing.T) { |
| 570 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 571 | if err := oo.Process_inter_adapter_message(tt.args.msg); reflect.TypeOf(err) != tt.wantErrType { |
| 572 | t.Errorf("Process_inter_adapter_message() error = %v, wantErr %v", |
| 573 | reflect.TypeOf(err), tt.wantErrType) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 574 | } |
| 575 | }) |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | func TestOpenOLT_Reboot_device(t *testing.T) { |
| 580 | type args struct { |
| 581 | device *voltha.Device |
| 582 | } |
| 583 | tests := []struct { |
| 584 | name string |
| 585 | fields *fields |
| 586 | args args |
| 587 | wantErr error |
| 588 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 589 | {"reboot_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 590 | {"reboot_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 591 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 592 | } |
| 593 | for _, tt := range tests { |
| 594 | t.Run(tt.name, func(t *testing.T) { |
| 595 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 596 | if err := oo.Reboot_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 597 | t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr) |
| 598 | } |
| 599 | }) |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | func TestOpenOLT_Receive_packet_out(t *testing.T) { |
| 604 | acts := []*ofp.OfpAction{ |
| 605 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))), |
| 606 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 607 | fu.Output(1), |
| 608 | } |
| 609 | type args struct { |
| 610 | deviceID string |
| 611 | egressPortNo int |
| 612 | packet *openflow_13.OfpPacketOut |
| 613 | } |
| 614 | pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" + |
| 615 | "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" + |
| 616 | "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")} |
| 617 | tests := []struct { |
| 618 | name string |
| 619 | fields *fields |
| 620 | args args |
| 621 | wantErr error |
| 622 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 623 | {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 624 | {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 625 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 626 | } |
| 627 | for _, tt := range tests { |
| 628 | t.Run(tt.name, func(t *testing.T) { |
| 629 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 630 | if err := oo.Receive_packet_out(tt.args.deviceID, tt.args.egressPortNo, tt.args.packet); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 631 | t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr) |
| 632 | } |
| 633 | }) |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | func TestOpenOLT_Reconcile_device(t *testing.T) { |
| 638 | type args struct { |
| 639 | device *voltha.Device |
| 640 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 641 | expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 642 | tests := []struct { |
| 643 | name string |
| 644 | fields *fields |
| 645 | args args |
| 646 | wantErr error |
| 647 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 648 | {"reconcile_device-1", &fields{}, args{}, expectedError}, |
| 649 | {"reconcile_device-2", &fields{}, args{}, expectedError}, |
| 650 | {"reconcile_device-3", &fields{}, args{}, expectedError}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 651 | } |
| 652 | for _, tt := range tests { |
| 653 | t.Run(tt.name, func(t *testing.T) { |
| 654 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 655 | if err := oo.Reconcile_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 656 | t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr) |
| 657 | } |
| 658 | }) |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | func TestOpenOLT_Reenable_device(t *testing.T) { |
| 663 | type args struct { |
| 664 | device *voltha.Device |
| 665 | } |
| 666 | tests := []struct { |
| 667 | name string |
| 668 | fields *fields |
| 669 | args args |
| 670 | wantErr error |
| 671 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 672 | {"reenable_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 673 | {"reenable_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 674 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 675 | } |
| 676 | for _, tt := range tests { |
| 677 | t.Run(tt.name, func(t *testing.T) { |
| 678 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 679 | if err := oo.Reenable_device(tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 680 | t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr) |
| 681 | } |
| 682 | }) |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | func TestOpenOLT_Revert_image_update(t *testing.T) { |
| 687 | type args struct { |
| 688 | device *voltha.Device |
| 689 | request *voltha.ImageDownload |
| 690 | } |
| 691 | tests := []struct { |
| 692 | name string |
| 693 | fields *fields |
| 694 | args args |
| 695 | want *voltha.ImageDownload |
| 696 | wantErr error |
| 697 | }{ |
| 698 | {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 699 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 700 | {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 701 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 702 | {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 703 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 704 | } |
| 705 | for _, tt := range tests { |
| 706 | t.Run(tt.name, func(t *testing.T) { |
| 707 | oo := testOltObject(tt.fields) |
| 708 | got, err := oo.Revert_image_update(tt.args.device, tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 709 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 710 | t.Log("error :", err) |
| 711 | } |
| 712 | }) |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | func TestOpenOLT_Self_test_device(t *testing.T) { |
| 717 | type args struct { |
| 718 | device *voltha.Device |
| 719 | } |
| 720 | tests := []struct { |
| 721 | name string |
| 722 | fields *fields |
| 723 | args args |
| 724 | wantErr error |
| 725 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 726 | {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 727 | {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 728 | {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 729 | } |
| 730 | for _, tt := range tests { |
| 731 | t.Run(tt.name, func(t *testing.T) { |
| 732 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 733 | if err := oo.Self_test_device(tt.args.device); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 734 | t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr) |
| 735 | } |
| 736 | }) |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | func TestOpenOLT_Start(t *testing.T) { |
| 741 | type args struct { |
| 742 | ctx context.Context |
| 743 | } |
| 744 | tests := []struct { |
| 745 | name string |
| 746 | fields *fields |
| 747 | args args |
| 748 | wantErr error |
| 749 | }{ |
| 750 | {"start-1", &fields{}, args{}, errors.New("start error")}, |
| 751 | } |
| 752 | for _, tt := range tests { |
| 753 | t.Run(tt.name, func(t *testing.T) { |
| 754 | oo := testOltObject(tt.fields) |
| 755 | if err := oo.Start(tt.args.ctx); err != nil { |
| 756 | t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr) |
| 757 | } |
| 758 | }) |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | func TestOpenOLT_Stop(t *testing.T) { |
| 763 | type args struct { |
| 764 | ctx context.Context |
| 765 | } |
| 766 | tests := []struct { |
| 767 | name string |
| 768 | fields *fields |
| 769 | args args |
| 770 | wantErr error |
| 771 | }{ |
| 772 | {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")}, |
| 773 | } |
| 774 | for _, tt := range tests { |
| 775 | t.Run(tt.name, func(t *testing.T) { |
| 776 | oo := testOltObject(tt.fields) |
| 777 | oo.Start(tt.args.ctx) |
| 778 | if err := oo.Stop(tt.args.ctx); err != nil { |
| 779 | t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr) |
| 780 | } |
| 781 | }) |
| 782 | } |
| 783 | } |
| 784 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 785 | func TestOpenOLT_Suppress_event(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 786 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 787 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 788 | } |
| 789 | tests := []struct { |
| 790 | name string |
| 791 | fields *fields |
| 792 | args args |
| 793 | wantErr error |
| 794 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 795 | {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 796 | {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 797 | {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 798 | } |
| 799 | for _, tt := range tests { |
| 800 | t.Run(tt.name, func(t *testing.T) { |
| 801 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 802 | if err := oo.Suppress_event(tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 803 | t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 804 | } |
| 805 | }) |
| 806 | } |
| 807 | } |
| 808 | |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 809 | func TestOpenOLT_Unsuppress_event(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 810 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 811 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 812 | } |
| 813 | tests := []struct { |
| 814 | name string |
| 815 | fields *fields |
| 816 | args args |
| 817 | wantErr error |
| 818 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 819 | {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 820 | {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 821 | {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 822 | } |
| 823 | for _, tt := range tests { |
| 824 | t.Run(tt.name, func(t *testing.T) { |
| 825 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 826 | if err := oo.Unsuppress_event(tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 827 | t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 828 | } |
| 829 | }) |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | func TestOpenOLT_Update_flows_bulk(t *testing.T) { |
| 834 | type args struct { |
| 835 | device *voltha.Device |
| 836 | flows *voltha.Flows |
| 837 | groups *voltha.FlowGroups |
| 838 | flowMetadata *voltha.FlowMetadata |
| 839 | } |
| 840 | tests := []struct { |
| 841 | name string |
| 842 | fields *fields |
| 843 | args args |
| 844 | wantErr error |
| 845 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 846 | {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 847 | {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 848 | {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 849 | } |
| 850 | for _, tt := range tests { |
| 851 | t.Run(tt.name, func(t *testing.T) { |
| 852 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 853 | if err := oo.Update_flows_bulk(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 854 | t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr) |
| 855 | } |
| 856 | }) |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | func TestOpenOLT_Update_flows_incrementally(t *testing.T) { |
| 861 | type args struct { |
| 862 | device *voltha.Device |
| 863 | flows *openflow_13.FlowChanges |
| 864 | groups *openflow_13.FlowGroupChanges |
| 865 | flowMetadata *voltha.FlowMetadata |
| 866 | } |
| 867 | |
| 868 | tests := []struct { |
| 869 | name string |
| 870 | fields *fields |
| 871 | args args |
| 872 | wantErr error |
| 873 | }{ |
| 874 | {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 875 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 876 | {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 877 | } |
| 878 | for _, tt := range tests { |
| 879 | t.Run(tt.name, func(t *testing.T) { |
| 880 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 881 | if err := oo.Update_flows_incrementally(tt.args.device, tt.args.flows, tt.args.groups, tt.args.flowMetadata); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 882 | t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr) |
| 883 | } |
| 884 | }) |
| 885 | } |
| 886 | } |
| 887 | |
| 888 | func TestOpenOLT_Update_pm_config(t *testing.T) { |
| 889 | type args struct { |
| 890 | device *voltha.Device |
| 891 | pmConfigs *voltha.PmConfigs |
| 892 | } |
| 893 | tests := []struct { |
| 894 | name string |
| 895 | fields *fields |
| 896 | args args |
| 897 | wantErr error |
| 898 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 899 | {"update_pm_config-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 900 | {"update_pm_config-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 901 | {"update_pm_config-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 902 | } |
| 903 | for _, tt := range tests { |
| 904 | t.Run(tt.name, func(t *testing.T) { |
| 905 | oo := testOltObject(tt.fields) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 906 | if err := oo.Update_pm_config(tt.args.device, tt.args.pmConfigs); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 907 | t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr) |
| 908 | } |
| 909 | |
| 910 | }) |
| 911 | } |
| 912 | } |
| 913 | |
| 914 | func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) { |
| 915 | type args struct { |
| 916 | agent *DeviceHandler |
| 917 | } |
| 918 | tests := []struct { |
| 919 | name string |
| 920 | fields *fields |
| 921 | args args |
| 922 | }{ |
| 923 | {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}}, |
| 924 | } |
| 925 | for _, tt := range tests { |
| 926 | t.Run(tt.name, func(t *testing.T) { |
| 927 | oo := testOltObject(tt.fields) |
| 928 | oo.deleteDeviceHandlerToMap(tt.args.agent) |
| 929 | if len(oo.deviceHandlers) > 0 { |
| 930 | t.Errorf("delete device manager failed") |
| 931 | } |
| 932 | }) |
| 933 | } |
| 934 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 935 | |
| 936 | func TestOpenOLT_Enable_port(t *testing.T) { |
| 937 | type args struct { |
| 938 | deviceID string |
| 939 | port *voltha.Port |
| 940 | } |
| 941 | tests := []struct { |
| 942 | name string |
| 943 | fields *fields |
| 944 | args args |
| 945 | wantErr bool |
| 946 | }{ |
| 947 | // TODO: Add test cases. |
| 948 | {"Enable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false}, |
| 949 | {"Enable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true}, |
| 950 | } |
| 951 | for _, tt := range tests { |
| 952 | t.Run(tt.name, func(t *testing.T) { |
| 953 | oo := testOltObject(tt.fields) |
| 954 | if err := oo.Enable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr { |
| 955 | t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 956 | } |
| 957 | }) |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | func TestOpenOLT_Disable_port(t *testing.T) { |
| 962 | type args struct { |
| 963 | deviceID string |
| 964 | port *voltha.Port |
| 965 | } |
| 966 | tests := []struct { |
| 967 | name string |
| 968 | fields *fields |
| 969 | args args |
| 970 | wantErr bool |
| 971 | }{ |
| 972 | // TODO: Add test cases. |
| 973 | {"Disable_port-1", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1}}, false}, |
| 974 | {"Disable_port-2", mockOlt(), args{deviceID: "olt", port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1}}, true}, |
| 975 | } |
| 976 | for _, tt := range tests { |
| 977 | t.Run(tt.name, func(t *testing.T) { |
| 978 | oo := testOltObject(tt.fields) |
| 979 | if err := oo.Disable_port(tt.args.deviceID, tt.args.port); (err != nil) != tt.wantErr { |
| 980 | t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 981 | } |
| 982 | }) |
| 983 | } |
| 984 | } |