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