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