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