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 | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 39 | ca "github.com/opencord/voltha-protos/v5/go/core_adapter" |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 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 | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 119 | request *ca.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 | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 180 | request *ca.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 | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 256 | request *ca.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 | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 285 | request *ca.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 |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 321 | want *ca.SwitchCapability |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 322 | wantErr error |
| 323 | }{ |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 324 | {"get_ofp_device_info-1", mockOlt(), args{mockDevice()}, &ca.SwitchCapability{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 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_RebootDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 352 | type args struct { |
| 353 | device *voltha.Device |
| 354 | } |
| 355 | tests := []struct { |
| 356 | name string |
| 357 | fields *fields |
| 358 | args args |
| 359 | wantErr error |
| 360 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 361 | {"reboot_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 362 | {"reboot_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 363 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 364 | } |
| 365 | for _, tt := range tests { |
| 366 | t.Run(tt.name, func(t *testing.T) { |
| 367 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 368 | 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] | 369 | t.Errorf("Reboot_device() error = %v, wantErr %v", err, tt.wantErr) |
| 370 | } |
| 371 | }) |
| 372 | } |
| 373 | } |
| 374 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 375 | func TestOpenOLT_SendPacketOut(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 376 | acts := []*ofp.OfpAction{ |
| 377 | fu.SetField(fu.Metadata_ofp(uint64(ofp.OfpInstructionType_OFPIT_WRITE_METADATA))), |
| 378 | fu.SetField(fu.VlanVid(uint32(ofp.OfpVlanId_OFPVID_PRESENT) | 101)), |
| 379 | fu.Output(1), |
| 380 | } |
| 381 | type args struct { |
| 382 | deviceID string |
| 383 | egressPortNo int |
| 384 | packet *openflow_13.OfpPacketOut |
| 385 | } |
| 386 | pktout := &ofp.OfpPacketOut{BufferId: 0, InPort: 1, Actions: acts, Data: []byte("AYDCAAAOAODsSE5TiMwCBwQA4OxITlIEBQUwLzUx" + |
| 387 | "BgIAFAgEMC81MQoJbG9jYWxob3N0EBwFAawbqqACAAAAoRAxLjMuNi4xLjQuMS40NDEz/gYAgMILAgD+GQCAwgkDAAAAAGQAAAAAAAAAAgICAgICAgL+" + |
| 388 | "GQCAwgoDAAAAAGQAAAAAAAAAAgICAgICAgIAAA==")} |
| 389 | tests := []struct { |
| 390 | name string |
| 391 | fields *fields |
| 392 | args args |
| 393 | wantErr error |
| 394 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 395 | {"receive_packet_out-1", mockOlt(), args{mockDevice().Id, 1, pktout}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 396 | {"receive_packet_out-2", mockOlt(), args{"1234", 1, pktout}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 397 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "1234"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 398 | } |
| 399 | for _, tt := range tests { |
| 400 | t.Run(tt.name, func(t *testing.T) { |
| 401 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 402 | if _, err := oo.SendPacketOut(context.Background(), &ca.PacketOut{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 403 | DeviceId: tt.args.deviceID, |
| 404 | EgressPortNo: uint32(tt.args.egressPortNo), |
| 405 | Packet: tt.args.packet}); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 406 | t.Errorf("Receive_packet_out() error = %v, wantErr %v", err, tt.wantErr) |
| 407 | } |
| 408 | }) |
| 409 | } |
| 410 | } |
| 411 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 412 | func TestOpenOLT_ReconcileDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 413 | type args struct { |
| 414 | device *voltha.Device |
| 415 | } |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 416 | expectedError := olterrors.NewErrInvalidValue(log.Fields{"device": nil}, nil) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 417 | tests := []struct { |
| 418 | name string |
| 419 | fields *fields |
| 420 | args args |
| 421 | wantErr error |
| 422 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 423 | {"reconcile_device-1", &fields{}, args{}, expectedError}, |
| 424 | {"reconcile_device-2", &fields{}, args{}, expectedError}, |
| 425 | {"reconcile_device-3", &fields{}, args{}, expectedError}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 426 | } |
| 427 | for _, tt := range tests { |
| 428 | t.Run(tt.name, func(t *testing.T) { |
| 429 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 430 | 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] | 431 | t.Errorf("Reconcile_device() error = %v, wantErr %v", err, tt.wantErr) |
| 432 | } |
| 433 | }) |
| 434 | } |
| 435 | } |
| 436 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 437 | func TestOpenOLT_ReEnableDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 438 | type args struct { |
| 439 | device *voltha.Device |
| 440 | } |
| 441 | tests := []struct { |
| 442 | name string |
| 443 | fields *fields |
| 444 | args args |
| 445 | wantErr error |
| 446 | }{ |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 447 | {"reenable_device-1", mockOlt(), args{mockDevice()}, nil}, |
| 448 | {"reenable_device-2", &fields{}, args{mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 449 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 450 | } |
| 451 | for _, tt := range tests { |
| 452 | t.Run(tt.name, func(t *testing.T) { |
| 453 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 454 | 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] | 455 | t.Errorf("Reenable_device() error = %v, wantErr %v", err, tt.wantErr) |
| 456 | } |
| 457 | }) |
| 458 | } |
| 459 | } |
| 460 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 461 | func TestOpenOLT_RevertImageUpdate(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 462 | type args struct { |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 463 | request *ca.ImageDownloadMessage |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 464 | } |
| 465 | tests := []struct { |
| 466 | name string |
| 467 | fields *fields |
| 468 | args args |
| 469 | want *voltha.ImageDownload |
| 470 | wantErr error |
| 471 | }{ |
| 472 | {"revert_image_update-1", &fields{}, args{}, &voltha.ImageDownload{Id: "Image1-ABC123XYZ"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 473 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 474 | {"revert_image_update-2", &fields{}, args{}, &voltha.ImageDownload{Id: "Image2-ABC123TYU"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 475 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 476 | {"revert_image_update-3", &fields{}, args{}, &voltha.ImageDownload{Id: "Image3-ABC123GTH"}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 477 | olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 478 | } |
| 479 | for _, tt := range tests { |
| 480 | t.Run(tt.name, func(t *testing.T) { |
| 481 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 482 | got, err := oo.RevertImageUpdate(context.Background(), tt.args.request) |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 483 | if err != tt.wantErr && got == nil { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 484 | t.Log("error :", err) |
| 485 | } |
| 486 | }) |
| 487 | } |
| 488 | } |
| 489 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 490 | func TestOpenOLT_SelfTestDevice(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 491 | type args struct { |
| 492 | device *voltha.Device |
| 493 | } |
| 494 | tests := []struct { |
| 495 | name string |
| 496 | fields *fields |
| 497 | args args |
| 498 | wantErr error |
| 499 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 500 | {"self_test_device-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 501 | {"self_test_device-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 502 | {"self_test_device-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 503 | } |
| 504 | for _, tt := range tests { |
| 505 | t.Run(tt.name, func(t *testing.T) { |
| 506 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 507 | if _, err := oo.SelfTestDevice(context.Background(), tt.args.device); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 508 | t.Errorf("Self_test_device() error = %v, wantErr %v", err, tt.wantErr) |
| 509 | } |
| 510 | }) |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | func TestOpenOLT_Start(t *testing.T) { |
| 515 | type args struct { |
| 516 | ctx context.Context |
| 517 | } |
| 518 | tests := []struct { |
| 519 | name string |
| 520 | fields *fields |
| 521 | args args |
| 522 | wantErr error |
| 523 | }{ |
| 524 | {"start-1", &fields{}, args{}, errors.New("start error")}, |
| 525 | } |
| 526 | for _, tt := range tests { |
| 527 | t.Run(tt.name, func(t *testing.T) { |
| 528 | oo := testOltObject(tt.fields) |
| 529 | if err := oo.Start(tt.args.ctx); err != nil { |
| 530 | t.Errorf("Start() error = %v, wantErr %v", err, tt.wantErr) |
| 531 | } |
| 532 | }) |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | func TestOpenOLT_Stop(t *testing.T) { |
| 537 | type args struct { |
| 538 | ctx context.Context |
| 539 | } |
| 540 | tests := []struct { |
| 541 | name string |
| 542 | fields *fields |
| 543 | args args |
| 544 | wantErr error |
| 545 | }{ |
| 546 | {"stop-1", &fields{exitChannel: make(chan int, 1)}, args{}, errors.New("stop error")}, |
| 547 | } |
| 548 | for _, tt := range tests { |
| 549 | t.Run(tt.name, func(t *testing.T) { |
| 550 | oo := testOltObject(tt.fields) |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 551 | if err := oo.Start(tt.args.ctx); err != nil { |
| 552 | t.Error(err) |
| 553 | } |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 554 | if err := oo.Stop(tt.args.ctx); err != nil { |
| 555 | t.Errorf("Stop() error = %v, wantErr %v", err, tt.wantErr) |
| 556 | } |
| 557 | }) |
| 558 | } |
| 559 | } |
| 560 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 561 | func TestOpenOLT_SuppressEvent(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 562 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 563 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 564 | } |
| 565 | tests := []struct { |
| 566 | name string |
| 567 | fields *fields |
| 568 | args args |
| 569 | wantErr error |
| 570 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 571 | {"suppress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 572 | {"suppress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 573 | {"suppress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 574 | } |
| 575 | for _, tt := range tests { |
| 576 | t.Run(tt.name, func(t *testing.T) { |
| 577 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 578 | if _, err := oo.SuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 579 | t.Errorf("Suppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 580 | } |
| 581 | }) |
| 582 | } |
| 583 | } |
| 584 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 585 | func TestOpenOLT_UnSuppressEvent(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 586 | type args struct { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 587 | filter *voltha.EventFilter |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 588 | } |
| 589 | tests := []struct { |
| 590 | name string |
| 591 | fields *fields |
| 592 | args args |
| 593 | wantErr error |
| 594 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 595 | {"unsupress_event-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 596 | {"unsupress_event-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 597 | {"unsupress_event-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 598 | } |
| 599 | for _, tt := range tests { |
| 600 | t.Run(tt.name, func(t *testing.T) { |
| 601 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 602 | if _, err := oo.UnSuppressEvent(context.Background(), tt.args.filter); err != tt.wantErr { |
Devmalya Paul | dd23a99 | 2019-11-14 07:06:31 +0000 | [diff] [blame] | 603 | t.Errorf("Unsuppress_event() error = %v, wantErr %v", err, tt.wantErr) |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 604 | } |
| 605 | }) |
| 606 | } |
| 607 | } |
| 608 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 609 | func TestOpenOLT_UpdateFlowsBulk(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 610 | type args struct { |
| 611 | device *voltha.Device |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 612 | flows *ofp.Flows |
| 613 | groups *ofp.FlowGroups |
| 614 | flowMetadata *ofp.FlowMetadata |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 615 | } |
| 616 | tests := []struct { |
| 617 | name string |
| 618 | fields *fields |
| 619 | args args |
| 620 | wantErr error |
| 621 | }{ |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 622 | {"update_flows_bulk-1", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 623 | {"update_flows_bulk-2", &fields{}, args{}, olterrors.ErrNotImplemented}, |
| 624 | {"update_flows_bulk-3", &fields{}, args{}, olterrors.ErrNotImplemented}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 625 | } |
| 626 | for _, tt := range tests { |
| 627 | t.Run(tt.name, func(t *testing.T) { |
| 628 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 629 | if _, err := oo.UpdateFlowsBulk(context.Background(), &ca.BulkFlows{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 630 | Device: tt.args.device, |
| 631 | Flows: tt.args.flows, |
| 632 | Groups: tt.args.groups, |
| 633 | FlowMetadata: tt.args.flowMetadata, |
| 634 | }); err != tt.wantErr { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 635 | t.Errorf("Update_flows_bulk() error = %v, wantErr %v", err, tt.wantErr) |
| 636 | } |
| 637 | }) |
| 638 | } |
| 639 | } |
| 640 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 641 | func TestOpenOLT_UpdateFlowsIncrementally(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 642 | type args struct { |
| 643 | device *voltha.Device |
| 644 | flows *openflow_13.FlowChanges |
| 645 | groups *openflow_13.FlowGroupChanges |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 646 | flowMetadata *ofp.FlowMetadata |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | tests := []struct { |
| 650 | name string |
| 651 | fields *fields |
| 652 | args args |
| 653 | wantErr error |
| 654 | }{ |
| 655 | {"update_flows_incrementally-1", &fields{}, args{device: mockDevice()}, |
Thomas Lee S | 94109f1 | 2020-03-03 16:39:29 +0530 | [diff] [blame] | 656 | olterrors.NewErrNotFound("device-handler", log.Fields{"device-id": "olt"}, nil)}, |
David K. Bainbridge | 794735f | 2020-02-11 21:01:37 -0800 | [diff] [blame] | 657 | {"update_flows_incrementally-2", mockOlt(), args{device: mockDevice()}, nil}, |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 658 | } |
| 659 | for _, tt := range tests { |
| 660 | t.Run(tt.name, func(t *testing.T) { |
| 661 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 662 | if _, err := oo.UpdateFlowsIncrementally(context.Background(), &ca.IncrementalFlows{ |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 663 | Device: tt.args.device, |
| 664 | Flows: tt.args.flows, |
| 665 | Groups: tt.args.groups, |
| 666 | FlowMetadata: tt.args.flowMetadata}); !reflect.DeepEqual(err, tt.wantErr) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 667 | t.Errorf("Update_flows_incrementally() error = %v, wantErr %v", err, tt.wantErr) |
| 668 | } |
| 669 | }) |
| 670 | } |
| 671 | } |
| 672 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 673 | func TestOpenOLT_UpdatePmConfig(t *testing.T) { |
cbabu | a9e04cc | 2019-10-03 12:35:45 +0530 | [diff] [blame] | 674 | type args struct { |
| 675 | device *voltha.Device |
| 676 | pmConfigs *voltha.PmConfigs |
| 677 | } |
| 678 | tests := []struct { |
| 679 | name string |
| 680 | fields *fields |
| 681 | args args |
| 682 | wantErr error |
| 683 | }{ |
Rohan Agrawal | da5e0b2 | 2020-05-20 11:10:26 +0000 | [diff] [blame] | 684 | {"update_pm_config-1", mockOlt(), args{device: mockDevice(), pmConfigs: &voltha.PmConfigs{DefaultFreq: 150, Grouped: false, FreqOverride: false}}, nil}, |
| 685 | {"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] | 686 | } |
| 687 | for _, tt := range tests { |
| 688 | t.Run(tt.name, func(t *testing.T) { |
| 689 | oo := testOltObject(tt.fields) |
khenaidoo | dc2116e | 2021-10-19 17:33:19 -0400 | [diff] [blame] | 690 | 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] | 691 | t.Errorf("Update_pm_config() error = %v, wantErr %v", err, tt.wantErr) |
| 692 | } |
| 693 | |
| 694 | }) |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | func TestOpenOLT_deleteDeviceHandlerToMap(t *testing.T) { |
| 699 | type args struct { |
| 700 | agent *DeviceHandler |
| 701 | } |
| 702 | tests := []struct { |
| 703 | name string |
| 704 | fields *fields |
| 705 | args args |
| 706 | }{ |
| 707 | {"delete_device_handler_map-1", mockOlt(), args{newMockDeviceHandler()}}, |
| 708 | } |
| 709 | for _, tt := range tests { |
| 710 | t.Run(tt.name, func(t *testing.T) { |
| 711 | oo := testOltObject(tt.fields) |
| 712 | oo.deleteDeviceHandlerToMap(tt.args.agent) |
| 713 | if len(oo.deviceHandlers) > 0 { |
| 714 | t.Errorf("delete device manager failed") |
| 715 | } |
| 716 | }) |
| 717 | } |
| 718 | } |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 719 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 720 | func TestOpenOLT_EnablePort(t *testing.T) { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 721 | type args struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 722 | port *voltha.Port |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 723 | } |
| 724 | tests := []struct { |
| 725 | name string |
| 726 | fields *fields |
| 727 | args args |
| 728 | wantErr bool |
| 729 | }{ |
| 730 | // TODO: Add test cases. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 731 | {"Enable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false}, |
| 732 | {"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] | 733 | } |
| 734 | for _, tt := range tests { |
| 735 | t.Run(tt.name, func(t *testing.T) { |
| 736 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 737 | if _, err := oo.EnablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 738 | t.Errorf("OpenOLT.Enable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 739 | } |
| 740 | }) |
| 741 | } |
| 742 | } |
| 743 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 744 | func TestOpenOLT_DisablePort(t *testing.T) { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 745 | type args struct { |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 746 | port *voltha.Port |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 747 | } |
| 748 | tests := []struct { |
| 749 | name string |
| 750 | fields *fields |
| 751 | args args |
| 752 | wantErr bool |
| 753 | }{ |
| 754 | // TODO: Add test cases. |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 755 | {"Disable_port-1", mockOlt(), args{port: &voltha.Port{Type: voltha.Port_PON_OLT, PortNo: 1, DeviceId: "olt"}}, false}, |
| 756 | {"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] | 757 | } |
| 758 | for _, tt := range tests { |
| 759 | t.Run(tt.name, func(t *testing.T) { |
| 760 | oo := testOltObject(tt.fields) |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 761 | if _, err := oo.DisablePort(context.Background(), tt.args.port); (err != nil) != tt.wantErr { |
kesavand | 39e0aa3 | 2020-01-28 20:58:50 -0500 | [diff] [blame] | 762 | t.Errorf("OpenOLT.Disable_port() error = %v, wantErr %v", err, tt.wantErr) |
| 763 | } |
| 764 | }) |
| 765 | } |
| 766 | } |