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