cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 1 | /* |
Joey Armstrong | 11f5a57 | 2024-01-12 19:11:32 -0500 | [diff] [blame] | 2 | * Copyright 2018-2024 Open Networking Foundation (ONF) and the ONF Contributors |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 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 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 22 | // Package core provides the utility for olt devices, flows and statistics |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 23 | package core |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 24 | |
| 25 | import ( |
| 26 | "context" |
| 27 | "errors" |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 28 | "reflect" |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 29 | "testing" |
| 30 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 31 | conf "github.com/opencord/voltha-lib-go/v7/pkg/config" |
| 32 | vgrpc "github.com/opencord/voltha-lib-go/v7/pkg/grpc" |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 33 | "github.com/opencord/voltha-protos/v5/go/openolt" |
| 34 | "github.com/stretchr/testify/assert" |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 35 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 36 | "github.com/opencord/voltha-lib-go/v7/pkg/events" |
| 37 | fu "github.com/opencord/voltha-lib-go/v7/pkg/flows" |
| 38 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
Scott Baker | dbd960e | 2020-02-28 08:57:51 -0800 | [diff] [blame] | 39 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/config" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 40 | "github.com/opencord/voltha-openolt-adapter/internal/pkg/olterrors" |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 41 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 42 | "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 43 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
| 44 | "github.com/opencord/voltha-protos/v5/go/voltha" |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 45 | ) |
| 46 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 47 | // mocks the OpenOLT struct. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 48 | type fields struct { |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 49 | deviceHandlers map[string]*DeviceHandler |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 50 | coreClient *vgrpc.Client |
Himani Chawla | cd40780 | 2020-12-10 12:08:59 +0530 | [diff] [blame] | 51 | eventProxy *events.EventProxy |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 52 | numOnus int |
| 53 | KVStoreAddress string |
| 54 | KVStoreType string |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 55 | exitChannel chan struct{} |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 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, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 72 | eventProxy: testOlt.eventProxy, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 73 | numOnus: testOlt.numOnus, |
Neha Sharma | 3f221ae | 2020-04-29 19:02:12 +0000 | [diff] [blame] | 74 | KVStoreAddress: testOlt.KVStoreAddress, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 75 | KVStoreType: testOlt.KVStoreType, |
| 76 | exitChannel: testOlt.exitChannel, |
| 77 | } |
| 78 | } |
| 79 | |
cbabu | bef8943 | 2019-10-18 11:47:27 +0200 | [diff] [blame] | 80 | // mockDevice mocks Device. |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 81 | func mockDevice() *voltha.Device { |
Kent Hagerman | f1db18b | 2020-07-08 13:38:15 -0400 | [diff] [blame] | 82 | return &voltha.Device{ |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 83 | Id: "olt", |
| 84 | Root: true, |
| 85 | ParentId: "logical_device", |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 86 | ProxyAddress: &voltha.Device_ProxyAddress{ |
| 87 | DeviceId: "olt", |
| 88 | DeviceType: "onu", |
| 89 | ChannelId: 1, |
| 90 | ChannelGroupId: 1, |
| 91 | }, |
| 92 | ConnectStatus: 1, |
| 93 | } |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | func TestNewOpenOLT(t *testing.T) { |
| 97 | tests := []struct { |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 98 | name string |
| 99 | fields *fields |
| 100 | configFlags *config.AdapterFlags |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 101 | cm *conf.ConfigManager |
Abhilash Laxmeshwar | f9942e9 | 2020-01-07 15:32:44 +0530 | [diff] [blame] | 102 | want *OpenOLT |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 103 | }{ |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 104 | {"newopenolt-1", &fields{}, &config.AdapterFlags{OnuNumber: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "etcd"}, &conf.ConfigManager{}, |
| 105 | &OpenOLT{numOnus: 1, KVStoreAddress: "1.1.1.1:1", KVStoreType: "etcd"}}, |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 106 | {"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] | 107 | &OpenOLT{numOnus: 2, KVStoreAddress: "2.2.2.2:2", KVStoreType: "etcd"}}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 108 | } |
| 109 | for _, tt := range tests { |
| 110 | t.Run(tt.name, func(t *testing.T) { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 111 | if got := NewOpenOLT(tt.fields.ctx, tt.fields.coreClient, |
Matteo Scandolo | dfa7a97 | 2020-11-06 13:03:40 -0800 | [diff] [blame] | 112 | 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] | 113 | t.Errorf("NewOpenOLT() error = %v, wantErr %v", got, tt.want) |
| 114 | } |
| 115 | }) |
| 116 | } |
| 117 | } |
| 118 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 119 | func TestOpenOLT_ActivateImageUpdate(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 120 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 121 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 122 | } |
| 123 | tests := []struct { |
| 124 | name string |
| 125 | fields *fields |
| 126 | args args |
| 127 | want *voltha.ImageDownload |
| 128 | wantErr error |
| 129 | }{ |
| 130 | {"activate_image_upate-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 131 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 132 | {"activate_image_upate-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123CDE"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 133 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 134 | {"activate_image_upate-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123EFG"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 135 | 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) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 140 | got, err := oo.ActivateImageUpdate(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 141 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 142 | t.Errorf("Activate_image_update() error = %v, wantErr %v", err, tt.wantErr) |
| 143 | } |
| 144 | }) |
| 145 | } |
| 146 | } |
| 147 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 148 | func TestOpenOLT_AdoptDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 149 | type args struct { |
| 150 | device *voltha.Device |
| 151 | } |
| 152 | var device = mockDevice() |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 153 | device.Id = "olt" |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 154 | nilDevice := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 155 | tests := []struct { |
| 156 | name string |
| 157 | fields *fields |
| 158 | args args |
| 159 | wantErr error |
| 160 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 161 | {"adopt_device-1", mockOlt(), args{}, nilDevice}, |
| 162 | {"adopt_device-2", mockOlt(), args{device}, nilDevice}, |
| 163 | {"adopt_device-3", mockOlt(), args{mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 164 | } |
| 165 | for _, tt := range tests { |
| 166 | t.Run(tt.name, func(t *testing.T) { |
| 167 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 168 | _, err := oo.AdoptDevice(context.Background(), tt.args.device) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 169 | if (err != nil) && (reflect.TypeOf(err) != |
| 170 | reflect.TypeOf(tt.wantErr)) && (tt.args.device == nil) { |
| 171 | t.Errorf("Adopt_device() error = %v, wantErr %v", err, tt.wantErr) |
| 172 | } |
| 173 | if err == nil { |
| 174 | t.Log("return'd nil") |
| 175 | } |
| 176 | }) |
| 177 | } |
| 178 | } |
| 179 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 180 | func TestOpenOLT_CancelImageDownload(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 181 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 182 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 183 | } |
| 184 | tests := []struct { |
| 185 | name string |
| 186 | fields *fields |
| 187 | args args |
| 188 | want *voltha.ImageDownload |
| 189 | wantErr error |
| 190 | }{ |
| 191 | {"cancel_image_download-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 192 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 193 | {"cancel_image_download-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123IJK"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 194 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 195 | {"cancel_image_download-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123KLM"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 196 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 197 | } |
| 198 | for _, tt := range tests { |
| 199 | t.Run(tt.name, func(t *testing.T) { |
| 200 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 201 | got, err := oo.CancelImageDownload(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 202 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 203 | t.Errorf("Cancel_image_download() error = %v, wantErr %v", err, tt.wantErr) |
| 204 | } |
| 205 | }) |
| 206 | } |
| 207 | } |
| 208 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 209 | func TestOpenOLT_DeleteDevice(t *testing.T) { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 210 | oo1 := testOltObject(&fields{}) |
| 211 | oo2 := testOltObject(&fields{}) |
| 212 | oo2.deviceHandlers = make(map[string]*DeviceHandler) |
| 213 | oo2.deviceHandlers[mockDevice().Id] = newMockDeviceHandler() |
| 214 | oo3 := testOltObject(&fields{}) |
| 215 | oo3.deviceHandlers = make(map[string]*DeviceHandler) |
| 216 | oo3.deviceHandlers[mockDevice().Id] = newMockDeviceHandler() |
| 217 | _, err := oo3.deviceHandlers[mockDevice().Id].Client.Reboot(context.Background(), &openolt.Empty{}) |
| 218 | assert.Nil(t, err) |
| 219 | |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 220 | type args struct { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 221 | oo *OpenOLT |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 222 | device *voltha.Device |
| 223 | } |
| 224 | tests := []struct { |
| 225 | name string |
| 226 | fields *fields |
| 227 | args args |
| 228 | wantErr error |
| 229 | }{ |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 230 | {"delete_device-1", &fields{}, args{oo1, mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 231 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 232 | {"delete_device-2", &fields{}, args{oo2, mockDevice()}, nil}, |
| 233 | {"delete_device-3", &fields{}, args{oo3, mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 234 | } |
| 235 | for _, tt := range tests { |
| 236 | t.Run(tt.name, func(t *testing.T) { |
Gustavo Silva | 41af912 | 2022-10-11 11:05:13 -0300 | [diff] [blame] | 237 | if _, err := tt.args.oo.DeleteDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 238 | t.Errorf("Delete_device() error = %v, wantErr %v", err, tt.wantErr) |
| 239 | } |
| 240 | }) |
| 241 | } |
| 242 | } |
| 243 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 244 | func TestOpenOLT_DisableDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 245 | type args struct { |
| 246 | device *voltha.Device |
| 247 | } |
| 248 | tests := []struct { |
| 249 | name string |
| 250 | fields *fields |
| 251 | args args |
| 252 | wantErr error |
| 253 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 254 | {"disable_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 255 | {"disable_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 256 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 257 | } |
| 258 | for _, tt := range tests { |
| 259 | t.Run(tt.name, func(t *testing.T) { |
| 260 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 261 | if _, err := oo.DisableDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 262 | t.Errorf("Disable_device() error = %v, wantErr %v", err, tt.wantErr) |
| 263 | } |
| 264 | }) |
| 265 | } |
| 266 | } |
| 267 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 268 | func TestOpenOLT_DownloadImage(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 269 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 270 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 271 | } |
| 272 | tests := []struct { |
| 273 | name string |
| 274 | fields *fields |
| 275 | args args |
| 276 | want *voltha.ImageDownload |
| 277 | wantErr error |
| 278 | }{ |
| 279 | {"download_image-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 280 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 281 | {"download_image-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123LKJ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 282 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 283 | {"download_image-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123RTY"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 284 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 285 | } |
| 286 | for _, tt := range tests { |
| 287 | t.Run(tt.name, func(t *testing.T) { |
| 288 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 289 | got, err := oo.DownloadImage(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 290 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 291 | t.Errorf("Download_image() error = %v, wantErr %v", err, tt.wantErr) |
| 292 | } |
| 293 | }) |
| 294 | } |
| 295 | } |
| 296 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 297 | func TestOpenOLT_GetImageDownloadStatus(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 298 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 299 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 300 | } |
| 301 | tests := []struct { |
| 302 | name string |
| 303 | fields *fields |
| 304 | args args |
| 305 | want *voltha.ImageDownload |
| 306 | wantErr error |
| 307 | }{ |
| 308 | {"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] | 309 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 310 | {"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] | 311 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 312 | {"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] | 313 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 314 | } |
| 315 | for _, tt := range tests { |
| 316 | t.Run(tt.name, func(t *testing.T) { |
| 317 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 318 | got, err := oo.GetImageDownloadStatus(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 319 | if err != tt.wantErr && got == nil { |
| 320 | t.Errorf("Get_image_download_status() got = %v want = %v error = %v, wantErr %v", |
| 321 | got, tt.want, err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 322 | } |
| 323 | }) |
| 324 | } |
| 325 | } |
| 326 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 327 | func TestOpenOLT_GetOfpDeviceInfo(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 328 | type args struct { |
| 329 | device *voltha.Device |
| 330 | } |
| 331 | tests := []struct { |
| 332 | name string |
| 333 | fields *fields |
| 334 | args args |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 335 | want *ca.SwitchCapability |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 336 | wantErr error |
| 337 | }{ |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 338 | {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ca.SwitchCapability{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 339 | Desc: &openflow_13.OfpDesc{ |
| 340 | MfrDesc: "VOLTHA Project", |
| 341 | HwDesc: "open_pon", |
| 342 | SwDesc: "open_pon", |
| 343 | }, |
| 344 | SwitchFeatures: &openflow_13.OfpSwitchFeatures{ |
| 345 | NBuffers: uint32(256), |
| 346 | NTables: uint32(2), |
| 347 | Capabilities: uint32(15), |
| 348 | }, |
| 349 | }, nil}, |
| 350 | {"get_ofp_device_info-2", &fields{}, args{mockDevice()}, nil, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 351 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 352 | } |
| 353 | for _, tt := range tests { |
| 354 | t.Run(tt.name, func(t *testing.T) { |
| 355 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 356 | got, err := oo.GetOfpDeviceInfo(context.Background(), tt.args.device) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 357 | if !reflect.DeepEqual(err, tt.wantErr) || !reflect.DeepEqual(got, tt.want) { |
| 358 | t.Errorf("Get_ofp_device_info() got = %v want = %v error = %v, wantErr = %v", |
| 359 | got, tt.want, err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 360 | } |
| 361 | }) |
| 362 | } |
| 363 | } |
| 364 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 365 | func TestOpenOLT_RebootDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 366 | type args struct { |
| 367 | device *voltha.Device |
| 368 | } |
| 369 | tests := []struct { |
| 370 | name string |
| 371 | fields *fields |
| 372 | args args |
| 373 | wantErr error |
| 374 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 375 | {"reboot_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 376 | {"reboot_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 377 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 378 | } |
| 379 | for _, tt := range tests { |
| 380 | t.Run(tt.name, func(t *testing.T) { |
| 381 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 382 | if _, err := oo.RebootDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 383 | t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr) |
| 384 | } |
| 385 | }) |
| 386 | } |
| 387 | } |
| 388 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 389 | func TestOpenOLT_SendPacketOut(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 390 | acts := []*ofp.OfpAction{ |
| 391 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))), |
| 392 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 393 | fu.Output(1), |
| 394 | } |
| 395 | type args struct { |
| 396 | deviceID string |
| 397 | egressPortNo int |
| 398 | packet *openflow_13.OfpPacketOut |
| 399 | } |
| 400 | pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" + |
| 401 | "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" + |
| 402 | "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")} |
| 403 | tests := []struct { |
| 404 | name string |
| 405 | fields *fields |
| 406 | args args |
| 407 | wantErr error |
| 408 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 409 | {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 410 | {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 411 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 412 | } |
| 413 | for _, tt := range tests { |
| 414 | t.Run(tt.name, func(t *testing.T) { |
| 415 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 416 | if _, err := oo.SendPacketOut(context.Background(), &ca.PacketOut{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 417 | DeviceId: tt.args.deviceID, |
| 418 | EgressPortNo: uint32(tt.args.egressPortNo), |
| 419 | Packet: tt.args.packet}); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 420 | t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr) |
| 421 | } |
| 422 | }) |
| 423 | } |
| 424 | } |
| 425 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 426 | func TestOpenOLT_ReconcileDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 427 | type args struct { |
| 428 | device *voltha.Device |
| 429 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 430 | expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 431 | tests := []struct { |
| 432 | name string |
| 433 | fields *fields |
| 434 | args args |
| 435 | wantErr error |
| 436 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 437 | {"reconcile_device-1", &fields{}, args{}, expectedError}, |
| 438 | {"reconcile_device-2", &fields{}, args{}, expectedError}, |
| 439 | {"reconcile_device-3", &fields{}, args{}, expectedError}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 440 | } |
| 441 | for _, tt := range tests { |
| 442 | t.Run(tt.name, func(t *testing.T) { |
| 443 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 444 | if _, err := oo.ReconcileDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 445 | t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr) |
| 446 | } |
| 447 | }) |
| 448 | } |
| 449 | } |
| 450 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 451 | func TestOpenOLT_ReEnableDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 452 | type args struct { |
| 453 | device *voltha.Device |
| 454 | } |
| 455 | tests := []struct { |
| 456 | name string |
| 457 | fields *fields |
| 458 | args args |
| 459 | wantErr error |
| 460 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 461 | {"reenable_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 462 | {"reenable_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 463 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
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) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 468 | if _, err := oo.ReEnableDevice(context.Background(), tt.args.device); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 469 | t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr) |
| 470 | } |
| 471 | }) |
| 472 | } |
| 473 | } |
| 474 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 475 | func TestOpenOLT_RevertImageUpdate(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 476 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 477 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 478 | } |
| 479 | tests := []struct { |
| 480 | name string |
| 481 | fields *fields |
| 482 | args args |
| 483 | want *voltha.ImageDownload |
| 484 | wantErr error |
| 485 | }{ |
| 486 | {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 487 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 488 | {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 489 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 490 | {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 491 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 492 | } |
| 493 | for _, tt := range tests { |
| 494 | t.Run(tt.name, func(t *testing.T) { |
| 495 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 496 | got, err := oo.RevertImageUpdate(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 497 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 498 | t.Log("error :", err) |
| 499 | } |
| 500 | }) |
| 501 | } |
| 502 | } |
| 503 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 504 | func TestOpenOLT_SelfTestDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 505 | type args struct { |
| 506 | device *voltha.Device |
| 507 | } |
| 508 | tests := []struct { |
| 509 | name string |
| 510 | fields *fields |
| 511 | args args |
| 512 | wantErr error |
| 513 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 514 | {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 515 | {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 516 | {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 517 | } |
| 518 | for _, tt := range tests { |
| 519 | t.Run(tt.name, func(t *testing.T) { |
| 520 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 521 | if _, err := oo.SelfTestDevice(context.Background(), tt.args.device); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 522 | t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr) |
| 523 | } |
| 524 | }) |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | func TestOpenOLT_Start(t *testing.T) { |
| 529 | type args struct { |
| 530 | ctx context.Context |
| 531 | } |
| 532 | tests := []struct { |
| 533 | name string |
| 534 | fields *fields |
| 535 | args args |
| 536 | wantErr error |
| 537 | }{ |
| 538 | {"start-1", &fields{}, args{}, errors.New("start error")}, |
| 539 | } |
| 540 | for _, tt := range tests { |
| 541 | t.Run(tt.name, func(t *testing.T) { |
| 542 | oo := testOltObject(tt.fields) |
| 543 | if err := oo.Start(tt.args.ctx); err != nil { |
| 544 | t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr) |
| 545 | } |
| 546 | }) |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | func TestOpenOLT_Stop(t *testing.T) { |
| 551 | type args struct { |
| 552 | ctx context.Context |
| 553 | } |
| 554 | tests := []struct { |
| 555 | name string |
| 556 | fields *fields |
| 557 | args args |
| 558 | wantErr error |
| 559 | }{ |
khenaidoo | efff76e | 2021-12-15 16:51:30 -0500 | [diff] [blame] | 560 | {"stop-1", &fields{exitChannel: make(chan struct{})}, args{}, errors.New("stop error")}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 561 | } |
| 562 | for _, tt := range tests { |
| 563 | t.Run(tt.name, func(t *testing.T) { |
| 564 | oo := testOltObject(tt.fields) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 565 | if err := oo.Start(tt.args.ctx); err != nil { |
| 566 | t.Error(err) |
| 567 | } |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 568 | if err := oo.Stop(tt.args.ctx); err != nil { |
| 569 | t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr) |
| 570 | } |
| 571 | }) |
| 572 | } |
| 573 | } |
| 574 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 575 | func TestOpenOLT_SuppressEvent(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 576 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 577 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 578 | } |
| 579 | tests := []struct { |
| 580 | name string |
| 581 | fields *fields |
| 582 | args args |
| 583 | wantErr error |
| 584 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 585 | {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 586 | {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 587 | {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 588 | } |
| 589 | for _, tt := range tests { |
| 590 | t.Run(tt.name, func(t *testing.T) { |
| 591 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 592 | if _, err := oo.SuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 593 | t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 594 | } |
| 595 | }) |
| 596 | } |
| 597 | } |
| 598 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 599 | func TestOpenOLT_UnSuppressEvent(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 600 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 601 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 602 | } |
| 603 | tests := []struct { |
| 604 | name string |
| 605 | fields *fields |
| 606 | args args |
| 607 | wantErr error |
| 608 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 609 | {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 610 | {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 611 | {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 612 | } |
| 613 | for _, tt := range tests { |
| 614 | t.Run(tt.name, func(t *testing.T) { |
| 615 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 616 | if _, err := oo.UnSuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 617 | t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 618 | } |
| 619 | }) |
| 620 | } |
| 621 | } |
| 622 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 623 | func TestOpenOLT_UpdateFlowsBulk(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 624 | type args struct { |
| 625 | device *voltha.Device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 626 | flows *ofp.Flows |
| 627 | groups *ofp.FlowGroups |
| 628 | flowMetadata *ofp.FlowMetadata |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 629 | } |
| 630 | tests := []struct { |
| 631 | name string |
| 632 | fields *fields |
| 633 | args args |
| 634 | wantErr error |
| 635 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 636 | {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 637 | {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 638 | {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 639 | } |
| 640 | for _, tt := range tests { |
| 641 | t.Run(tt.name, func(t *testing.T) { |
| 642 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 643 | if _, err := oo.UpdateFlowsBulk(context.Background(), &ca.BulkFlows{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 644 | Device: tt.args.device, |
| 645 | Flows: tt.args.flows, |
| 646 | Groups: tt.args.groups, |
| 647 | FlowMetadata: tt.args.flowMetadata, |
| 648 | }); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 649 | t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr) |
| 650 | } |
| 651 | }) |
| 652 | } |
| 653 | } |
| 654 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 655 | func TestOpenOLT_UpdateFlowsIncrementally(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 656 | type args struct { |
| 657 | device *voltha.Device |
| 658 | flows *openflow_13.FlowChanges |
| 659 | groups *openflow_13.FlowGroupChanges |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 660 | flowMetadata *ofp.FlowMetadata |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | tests := []struct { |
| 664 | name string |
| 665 | fields *fields |
| 666 | args args |
| 667 | wantErr error |
| 668 | }{ |
| 669 | {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 670 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 671 | {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 672 | } |
| 673 | for _, tt := range tests { |
| 674 | t.Run(tt.name, func(t *testing.T) { |
| 675 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 676 | if _, err := oo.UpdateFlowsIncrementally(context.Background(), &ca.IncrementalFlows{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 677 | Device: tt.args.device, |
| 678 | Flows: tt.args.flows, |
| 679 | Groups: tt.args.groups, |
| 680 | FlowMetadata: tt.args.flowMetadata}); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 681 | t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr) |
| 682 | } |
| 683 | }) |
| 684 | } |
| 685 | } |
| 686 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 687 | func TestOpenOLT_UpdatePmConfig(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 688 | type args struct { |
| 689 | device *voltha.Device |
| 690 | pmConfigs *voltha.PmConfigs |
| 691 | } |
| 692 | tests := []struct { |
| 693 | name string |
| 694 | fields *fields |
| 695 | args args |
| 696 | wantErr error |
| 697 | }{ |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 698 | {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil}, |
| 699 | {"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] | 700 | } |
| 701 | for _, tt := range tests { |
| 702 | t.Run(tt.name, func(t *testing.T) { |
| 703 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 704 | if _, err := oo.UpdatePmConfig(context.Background(), &ca.PmConfigsInfo{DeviceId: tt.args.device.Id, PmConfigs: tt.args.pmConfigs}); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 705 | t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr) |
| 706 | } |
| 707 | |
| 708 | }) |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) { |
| 713 | type args struct { |
| 714 | agent *DeviceHandler |
| 715 | } |
| 716 | tests := []struct { |
| 717 | name string |
| 718 | fields *fields |
| 719 | args args |
| 720 | }{ |
| 721 | {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}}, |
| 722 | } |
| 723 | for _, tt := range tests { |
| 724 | t.Run(tt.name, func(t *testing.T) { |
| 725 | oo := testOltObject(tt.fields) |
| 726 | oo.deleteDeviceHandlerToMap(tt.args.agent) |
| 727 | if len(oo.deviceHandlers) > 0 { |
| 728 | t.Errorf("delete device manager failed") |
| 729 | } |
| 730 | }) |
| 731 | } |
| 732 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 733 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 734 | func TestOpenOLT_EnablePort(t *testing.T) { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 735 | type args struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 736 | port *voltha.Port |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 737 | } |
| 738 | tests := []struct { |
| 739 | name string |
| 740 | fields *fields |
| 741 | args args |
| 742 | wantErr bool |
| 743 | }{ |
| 744 | // TODO: Add test cases. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 745 | {"Enable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false}, |
| 746 | {"Enable_port-2", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1, DeviceId: "olt"}}, true}, |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 747 | } |
| 748 | for _, tt := range tests { |
| 749 | t.Run(tt.name, func(t *testing.T) { |
| 750 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 751 | if _, err := oo.EnablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 752 | t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 753 | } |
| 754 | }) |
| 755 | } |
| 756 | } |
| 757 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 758 | func TestOpenOLT_DisablePort(t *testing.T) { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 759 | type args struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 760 | port *voltha.Port |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 761 | } |
| 762 | tests := []struct { |
| 763 | name string |
| 764 | fields *fields |
| 765 | args args |
| 766 | wantErr bool |
| 767 | }{ |
| 768 | // TODO: Add test cases. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 769 | {"Disable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false}, |
| 770 | {"Disable_port-2", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_ETHERNET_NNI, PortNo: 1, DeviceId: "olt"}}, true}, |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 771 | } |
| 772 | for _, tt := range tests { |
| 773 | t.Run(tt.name, func(t *testing.T) { |
| 774 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 775 | if _, err := oo.DisablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 776 | t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 777 | } |
| 778 | }) |
| 779 | } |
| 780 | } |