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