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