kdarapu | 3248f9a | 2019-10-03 13:54:52 +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 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +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 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 17 | // Package mocks provides the mocks for openolt-adapter. |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 18 | package mocks |
| 19 | |
| 20 | import ( |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 21 | "context" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 22 | "encoding/json" |
| 23 | "errors" |
| 24 | "strconv" |
| 25 | "strings" |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 26 | "time" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 27 | |
khenaidoo | 106c61a | 2021-08-11 18:05:46 -0400 | [diff] [blame] | 28 | "github.com/opencord/voltha-lib-go/v7/pkg/db/kvstore" |
| 29 | "github.com/opencord/voltha-lib-go/v7/pkg/log" |
| 30 | ofp "github.com/opencord/voltha-protos/v5/go/openflow_13" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 31 | ) |
| 32 | |
| 33 | const ( |
| 34 | // MeterConfig meter to extarct meter |
| 35 | MeterConfig = "meter_id" |
| 36 | // TpIDPathSuffix to extract Techprofile |
| 37 | TpIDPathSuffix = "tp_id" |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 38 | // FlowIDpool to extract Flow ids |
| 39 | FlowIDpool = "flow_id_pool" |
| 40 | // FlowIDs to extract flow_ids |
| 41 | FlowIDs = "flow_ids" |
| 42 | // FlowIDInfo to extract flowId info |
| 43 | FlowIDInfo = "flow_id_info" |
| 44 | // GemportIDs to gemport_ids |
| 45 | GemportIDs = "gemport_ids" |
| 46 | // AllocIDs to extract alloc_ids |
| 47 | AllocIDs = "alloc_ids" |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 48 | //FlowGroup flow_groups/<flow_group_id> |
| 49 | FlowGroup = "flow_groups" |
| 50 | //FlowGroupCached flow_groups_cached/<flow_group_id> |
| 51 | FlowGroupCached = "flow_groups_cached" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 52 | //OnuPacketIn to extract gem port from packet-in |
| 53 | OnuPacketIn = "onu_packetin" |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 54 | // OnuGemInfoPath has path on the kvstore to store OnuGemInfo info per PON interface |
| 55 | OnuGemInfoPath = "onu_gem_info" |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 56 | ) |
| 57 | |
| 58 | // MockKVClient mocks the AdapterProxy interface. |
| 59 | type MockKVClient struct { |
| 60 | } |
| 61 | |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 62 | // OnuGemInfo holds onu information along with gem port list and uni port list |
| 63 | type OnuGemInfo struct { |
| 64 | OnuID uint32 |
| 65 | SerialNumber string |
| 66 | IntfID uint32 |
| 67 | GemPorts []uint32 |
| 68 | UniPorts []uint32 |
| 69 | } |
| 70 | |
| 71 | // GroupInfo holds group information |
| 72 | type GroupInfo struct { |
| 73 | GroupID uint32 |
| 74 | OutPorts []uint32 |
| 75 | } |
| 76 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 77 | // List mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 78 | func (kvclient *MockKVClient) List(ctx context.Context, key string) (map[string]*kvstore.KVPair, error) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 79 | if key != "" { |
| 80 | maps := make(map[string]*kvstore.KVPair) |
| 81 | maps[key] = &kvstore.KVPair{Key: key} |
| 82 | return maps, nil |
| 83 | } |
| 84 | return nil, errors.New("key didn't find") |
| 85 | } |
| 86 | |
| 87 | // Get mock function implementation for KVClient |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 88 | // nolint: gocyclo |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 89 | func (kvclient *MockKVClient) Get(ctx context.Context, key string) (*kvstore.KVPair, error) { |
Girish Gowdra | a09aeab | 2020-09-14 16:30:52 -0700 | [diff] [blame] | 90 | logger.Debugw(ctx, "Get of MockKVClient called", log.Fields{"key": key}) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 91 | if key != "" { |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 92 | if strings.Contains(key, "meter_id/{0,62,8}/{upstream}") { |
| 93 | meterConfig := ofp.OfpMeterConfig{ |
| 94 | Flags: 0, |
| 95 | MeterId: 1, |
| 96 | } |
| 97 | str, _ := json.Marshal(meterConfig) |
| 98 | return kvstore.NewKVPair(key, string(str), "mock", 3000, 1), nil |
| 99 | } |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 100 | if strings.Contains(key, MeterConfig) { |
| 101 | var bands []*ofp.OfpMeterBandHeader |
| 102 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK, |
| 103 | Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 2}}}) |
| 104 | |
| 105 | bands = append(bands, &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DSCP_REMARK, |
| 106 | Rate: 1024, Data: &ofp.OfpMeterBandHeader_DscpRemark{DscpRemark: &ofp.OfpMeterBandDscpRemark{PrecLevel: 3}}}) |
| 107 | |
Gamze Abaka | fee3639 | 2019-10-03 11:17:24 +0000 | [diff] [blame] | 108 | sep := strings.Split(key, "/")[1] |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 109 | val, _ := strconv.ParseInt(strings.Split(sep, ",")[1], 10, 32) |
| 110 | if uint32(val) > 1 { |
| 111 | meterConfig := &ofp.OfpMeterConfig{MeterId: uint32(val), Bands: bands} |
| 112 | str, _ := json.Marshal(meterConfig) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 113 | |
| 114 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 115 | } |
| 116 | |
| 117 | if strings.Contains(key, "meter_id/{1,1,1}/{downstream}") { |
| 118 | |
| 119 | band1 := &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 1000, BurstSize: 5000} |
| 120 | band2 := &ofp.OfpMeterBandHeader{Type: ofp.OfpMeterBandType_OFPMBT_DROP, Rate: 2000, BurstSize: 5000} |
| 121 | bands := []*ofp.OfpMeterBandHeader{band1, band2} |
| 122 | ofpMeterConfig := &ofp.OfpMeterConfig{Flags: 1, MeterId: 1, Bands: bands} |
| 123 | str, _ := json.Marshal(ofpMeterConfig) |
| 124 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 125 | } |
| 126 | if uint32(val) == 1 { |
| 127 | return nil, nil |
| 128 | } |
| 129 | return nil, errors.New("invalid meter") |
| 130 | } |
| 131 | if strings.Contains(key, TpIDPathSuffix) { |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 132 | data := []uint32{64} |
| 133 | str, _ := json.Marshal(data) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 134 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 135 | } |
| 136 | if strings.Contains(key, FlowIDpool) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 137 | logger.Debug(ctx, "Error Error Error Key:", FlowIDpool) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 138 | data := make(map[string]interface{}) |
| 139 | data["pool"] = "1024" |
| 140 | data["start_idx"] = 1 |
| 141 | data["end_idx"] = 1024 |
| 142 | str, _ := json.Marshal(data) |
| 143 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 144 | } |
| 145 | if strings.Contains(key, FlowIDs) { |
| 146 | data := []uint32{1, 2} |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 147 | logger.Debug(ctx, "Error Error Error Key:", FlowIDs) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 148 | str, _ := json.Marshal(data) |
| 149 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 150 | } |
Esin Karaman | d519bbf | 2020-07-01 11:16:03 +0000 | [diff] [blame] | 151 | |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 152 | if strings.Contains(key, GemportIDs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 153 | logger.Debug(ctx, "Error Error Error Key:", GemportIDs) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 154 | data := []uint32{1} |
| 155 | str, _ := json.Marshal(data) |
kdarapu | b26b450 | 2019-10-05 03:02:33 +0530 | [diff] [blame] | 156 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 157 | } |
| 158 | if strings.Contains(key, AllocIDs) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 159 | logger.Debug(ctx, "Error Error Error Key:", AllocIDs) |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 160 | data := []uint32{1} |
| 161 | str, _ := json.Marshal(data) |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 162 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 163 | } |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 164 | if strings.Contains(key, FlowGroup) || strings.Contains(key, FlowGroupCached) { |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 165 | logger.Debug(ctx, "Error Error Error Key:", FlowGroup) |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 166 | groupInfo := GroupInfo{ |
Esin Karaman | ccb714b | 2019-11-29 15:02:06 +0000 | [diff] [blame] | 167 | GroupID: 2, |
| 168 | OutPorts: []uint32{1}, |
| 169 | } |
| 170 | str, _ := json.Marshal(&groupInfo) |
| 171 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 172 | } |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 173 | if strings.Contains(key, OnuPacketIn) { |
| 174 | return getPacketInGemPort(key) |
| 175 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 176 | |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 177 | if strings.Contains(key, OnuGemInfoPath) { |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 178 | var data []OnuGemInfo |
Girish Gowdra | fb3d610 | 2020-10-16 16:32:36 -0700 | [diff] [blame] | 179 | str, _ := json.Marshal(data) |
| 180 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 181 | } |
Girish Gowdra | 8a0bdcd | 2021-05-13 12:31:04 -0700 | [diff] [blame] | 182 | |
Esin Karaman | df392e1 | 2020-12-16 13:33:09 +0000 | [diff] [blame] | 183 | //Interface, GEM port path |
| 184 | if strings.Contains(key, "0,255") { |
| 185 | //return onuID, uniID associated with the given interface and GEM port |
| 186 | data := []uint32{1, 0} |
| 187 | str, _ := json.Marshal(data) |
| 188 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 189 | } |
| 190 | //Interface, GEM port path |
| 191 | if strings.Contains(key, "0,257") { |
| 192 | //return onuID, uniID associated with the given interface and GEM port |
| 193 | data := []uint32{1, 0} |
| 194 | str, _ := json.Marshal(data) |
| 195 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 196 | } |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 197 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 198 | maps := make(map[string]*kvstore.KVPair) |
| 199 | maps[key] = &kvstore.KVPair{Key: key} |
| 200 | return maps[key], nil |
| 201 | } |
| 202 | return nil, errors.New("key didn't find") |
| 203 | } |
| 204 | |
pnalmas | 04ede3b | 2025-01-16 18:05:27 +0530 | [diff] [blame] | 205 | // GetWithPrefix mock function implementation for KVClient |
| 206 | func (kvclient *MockKVClient) GetWithPrefix(ctx context.Context, prefix string) (map[string]*kvstore.KVPair, error) { |
| 207 | result := make(map[string]*kvstore.KVPair) |
| 208 | |
| 209 | // Get all the key-value pairs from the KV store |
| 210 | kvPairs, err := kvclient.List(ctx, "") |
| 211 | if err != nil { |
| 212 | return nil, err |
| 213 | } |
| 214 | |
| 215 | // Iterate through all the keys in the KV store |
| 216 | for key, kvPair := range kvPairs { |
| 217 | // Check if the key has the specified prefix |
| 218 | if strings.HasPrefix(key, prefix) { |
| 219 | // Add the KVPair to the result map |
| 220 | result[key] = kvPair |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | return result, nil |
| 225 | } |
| 226 | |
| 227 | // GetWithPrefixKeysOnly mock function implementation for KVClient |
| 228 | func (kvclient *MockKVClient) GetWithPrefixKeysOnly(ctx context.Context, prefix string) ([]string, error) { |
| 229 | keys := make([]string, 0) |
| 230 | |
| 231 | // Get all the key-value pairs from the KV store |
| 232 | kvPairs, err := kvclient.List(ctx, "") |
| 233 | if err != nil { |
| 234 | return nil, err |
| 235 | } |
| 236 | |
| 237 | // Iterate through all the keys in the KV store |
| 238 | for key := range kvPairs { |
| 239 | // Check if the key has the specified prefix |
| 240 | if strings.HasPrefix(key, prefix) { |
| 241 | // Add the key to the result slice |
| 242 | keys = append(keys, key) |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | return keys, nil |
| 247 | } |
| 248 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 249 | // getPacketInGemPort returns the GEM port associated with the given key |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 250 | func getPacketInGemPort(key string) (*kvstore.KVPair, error) { |
| 251 | //parse interface, onu, uni, vlan, priority values |
| 252 | arr := getParamsFromPacketInKey(key) |
| 253 | |
| 254 | if len(arr) < 5 { |
| 255 | return nil, errors.New("key didn't find") |
| 256 | } |
| 257 | if arr[0] == "1" && arr[1] == "1" && arr[2] == "3" && arr[3] == "0" && arr[4] == "0" { |
| 258 | str, _ := json.Marshal(3) |
| 259 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 260 | } |
| 261 | if arr[0] == "2" && arr[1] == "2" && arr[2] == "4" && arr[3] == "549" && arr[4] == "0" { |
| 262 | str, _ := json.Marshal(4) |
| 263 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 264 | } |
| 265 | if arr[0] == "1" && arr[1] == "2" && arr[2] == "2" && arr[3] == "48" && arr[4] == "7" { |
| 266 | str, _ := json.Marshal(2) |
| 267 | return kvstore.NewKVPair(key, str, "mock", 3000, 1), nil |
| 268 | } |
| 269 | return nil, errors.New("key didn't find") |
| 270 | } |
| 271 | |
Joey Armstrong | 3f0e242 | 2023-07-05 18:25:41 -0400 | [diff] [blame] | 272 | // getParamsFromPacketInKey parse packetIn key that is in the format of "onu_packetin/{1,1,1,1,2}" |
Esin Karaman | 7fb80c2 | 2020-07-16 14:23:33 +0000 | [diff] [blame] | 273 | func getParamsFromPacketInKey(key string) []string { |
| 274 | //return intfID, onuID, uniID, vlanID, priority |
| 275 | firstIndex := strings.Index(key, "{") |
| 276 | lastIndex := strings.Index(key, "}") |
| 277 | if firstIndex == -1 && lastIndex == -1 { |
| 278 | return []string{} |
| 279 | } |
| 280 | arr := strings.Split(key[firstIndex+1:lastIndex], ",") |
| 281 | if len(arr) < 5 { |
| 282 | return []string{} |
| 283 | } |
| 284 | return arr |
| 285 | } |
| 286 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 287 | // Put mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 288 | func (kvclient *MockKVClient) Put(ctx context.Context, key string, value interface{}) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 289 | if key != "" { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 290 | return nil |
| 291 | } |
| 292 | return errors.New("key didn't find") |
| 293 | } |
| 294 | |
| 295 | // Delete mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 296 | func (kvclient *MockKVClient) Delete(ctx context.Context, key string) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 297 | if key == "" { |
| 298 | return errors.New("key didn't find") |
| 299 | } |
| 300 | return nil |
| 301 | } |
| 302 | |
serkant.uluderya | 7b8211e | 2021-02-24 16:39:18 +0300 | [diff] [blame] | 303 | // DeleteWithPrefix mock function implementation for KVClient |
| 304 | func (kvclient *MockKVClient) DeleteWithPrefix(ctx context.Context, prefixKey string) error { |
| 305 | if prefixKey == "" { |
| 306 | return errors.New("key didn't find") |
| 307 | } |
| 308 | return nil |
| 309 | } |
| 310 | |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 311 | // Reserve mock function implementation for KVClient |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 312 | func (kvclient *MockKVClient) Reserve(ctx context.Context, key string, value interface{}, ttl time.Duration) (interface{}, error) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 313 | if key != "" { |
| 314 | maps := make(map[string]*kvstore.KVPair) |
| 315 | maps[key] = &kvstore.KVPair{Key: key} |
| 316 | return maps[key], nil |
| 317 | } |
| 318 | return nil, errors.New("key didn't find") |
| 319 | } |
| 320 | |
| 321 | // ReleaseReservation mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 322 | func (kvclient *MockKVClient) ReleaseReservation(ctx context.Context, key string) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 323 | // return nil |
| 324 | if key == "" { |
| 325 | return errors.New("key didn't find") |
| 326 | } |
| 327 | return nil |
| 328 | } |
| 329 | |
| 330 | // ReleaseAllReservations mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 331 | func (kvclient *MockKVClient) ReleaseAllReservations(ctx context.Context) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 332 | return nil |
| 333 | } |
| 334 | |
| 335 | // RenewReservation mock function implementation for KVClient |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 336 | func (kvclient *MockKVClient) RenewReservation(ctx context.Context, key string) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 337 | // return nil |
| 338 | if key == "" { |
| 339 | return errors.New("key didn't find") |
| 340 | } |
| 341 | return nil |
| 342 | } |
| 343 | |
| 344 | // Watch mock function implementation for KVClient |
Scott Baker | e701b86 | 2020-02-20 16:19:16 -0800 | [diff] [blame] | 345 | func (kvclient *MockKVClient) Watch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 346 | return nil |
| 347 | // if key == "" { |
| 348 | // return nil |
| 349 | // } |
| 350 | // return &kvstore.Event{EventType: 1, Key: key} |
| 351 | } |
| 352 | |
| 353 | // AcquireLock mock function implementation for KVClient |
Neha Sharma | cc65696 | 2020-04-14 14:26:11 +0000 | [diff] [blame] | 354 | func (kvclient *MockKVClient) AcquireLock(ctx context.Context, lockName string, timeout time.Duration) error { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 355 | return nil |
| 356 | } |
| 357 | |
| 358 | // ReleaseLock mock function implementation for KVClient |
| 359 | func (kvclient *MockKVClient) ReleaseLock(lockName string) error { |
| 360 | return nil |
| 361 | } |
| 362 | |
| 363 | // IsConnectionUp mock function implementation for KVClient |
Matteo Scandolo | 945e401 | 2019-12-12 14:16:11 -0800 | [diff] [blame] | 364 | func (kvclient *MockKVClient) IsConnectionUp(ctx context.Context) bool { |
| 365 | // timeout in second |
npujar | ec5762e | 2020-01-01 14:08:48 +0530 | [diff] [blame] | 366 | t, _ := ctx.Deadline() |
Kent Hagerman | e6ff101 | 2020-07-14 15:07:53 -0400 | [diff] [blame] | 367 | return t.Second()-time.Now().Second() >= 1 |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | // CloseWatch mock function implementation for KVClient |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 371 | func (kvclient *MockKVClient) CloseWatch(ctx context.Context, key string, ch chan *kvstore.Event) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | // Close mock function implementation for KVClient |
Neha Sharma | 96b7bf2 | 2020-06-15 10:37:32 +0000 | [diff] [blame] | 375 | func (kvclient *MockKVClient) Close(ctx context.Context) { |
kdarapu | 3248f9a | 2019-10-03 13:54:52 +0530 | [diff] [blame] | 376 | } |