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" |
| 29 | "sync" |
| 30 | "testing" |
| 31 | |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 32 | com "github.com/opencord/voltha-lib-go/v3/pkg/adapters/common" |
| 33 | fu "github.com/opencord/voltha-lib-go/v3/pkg/flows" |
| 34 | "github.com/opencord/voltha-lib-go/v3/pkg/kafka" |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 35 | "github.com/opencord/voltha-lib-go/v3/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 36 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 37 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 38 | ic "github.com/opencord/voltha-protos/v3/go/inter_container" |
| 39 | "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 40 | ofp "github.com/opencord/voltha-protos/v3/go/openflow_13" |
| 41 | "github.com/opencord/voltha-protos/v3/go/voltha" |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 42 | ) |
| 43 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 44 | // mocks the OpenOLT struct. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 45 | type fields struct { |
| 46 | deviceHandlers map[string]*DeviceHandler |
| 47 | coreProxy *com.CoreProxy |
| 48 | adapterProxy *com.AdapterProxy |
| 49 | eventProxy *com.EventProxy |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 50 | kafkaICProxy kafka.InterContainerProxy |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 51 | numOnus int |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 52 | KVStoreAddress string |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 53 | KVStoreType string |
| 54 | exitChannel chan int |
| 55 | lockDeviceHandlersMap sync.RWMutex |
| 56 | ctx context.Context |
| 57 | } |
| 58 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 59 | // mockOlt mocks OpenOLT struct. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 60 | func mockOlt() *fields { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 61 | dh := newMockDeviceHandler() |
| 62 | newOlt := &fields{} |
| 63 | newOlt.deviceHandlers = map[string]*DeviceHandler{} |
| 64 | newOlt.deviceHandlers[dh.device.Id] = dh |
| 65 | return newOlt |
| 66 | } |
| 67 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 68 | // testOltObject maps fields type to OpenOLt type. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 69 | func testOltObject(testOlt *fields) *OpenOLT { |
| 70 | return &OpenOLT{ |
| 71 | deviceHandlers: testOlt.deviceHandlers, |
| 72 | coreProxy: testOlt.coreProxy, |
| 73 | adapterProxy: testOlt.adapterProxy, |
| 74 | eventProxy: testOlt.eventProxy, |
| 75 | kafkaICProxy: testOlt.kafkaICProxy, |
| 76 | numOnus: testOlt.numOnus, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 77 | KVStoreAddress: testOlt.KVStoreAddress, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 78 | KVStoreType: testOlt.KVStoreType, |
| 79 | exitChannel: testOlt.exitChannel, |
| 80 | } |
| 81 | } |
| 82 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 83 | // mockDevice mocks Device. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 84 | func mockDevice() *voltha.Device { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 85 | return &voltha.Device{ |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 86 | Id: "olt", |
| 87 | Root: true, |
| 88 | ParentId: "logical_device", |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 89 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 90 | DeviceId: "olt", |
| 91 | DeviceType: "onu", |
| 92 | ChannelId: 1, |
| 93 | ChannelGroupId: 1, |
| 94 | }, |
| 95 | ConnectStatus: 1, |
| 96 | } |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | func TestNewOpenOLT(t *testing.T) { |
| 100 | tests := []struct { |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 101 | name string |
| 102 | fields *fields |
| 103 | configFlags *config.AdapterFlags |
| 104 | want *OpenOLT |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 105 | }{ |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 106 | {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}, |
| 107 | &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "consul"}}, |
| 108 | {"newopenolt-2", &fields{}, &config.AdapterFlags{OnuNumber: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}, |
| 109 | &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}}, |
| 110 | {"newopenolt-3", &fields{}, &config.AdapterFlags{OnuNumber: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}, |
| 111 | &OpenOLT{numOnus: 3, KVStoreAddress: "3.3.3.3:3", KVStoreType: "consul"}}, |
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, |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 116 | 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] | 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) |
| 731 | oo.Start(tt.args.ctx) |
| 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 | } |