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