Skip to content

Commit a90eee0

Browse files
rhalsteabocon13
authored andcommitted
Changes needed to support VBAR separator.
1 parent d0c3744 commit a90eee0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

tests/fakes/fake_db_connector.cc

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ struct RedisDbKey {
2121

2222
// Parses a string as a RedisDB key. If the key is not in our expected format we
2323
// return a status failure.
24-
absl::StatusOr<RedisDbKey> GetRedisDbKey(const std::string& key) {
25-
constexpr char kDelimiter[] = ":";
26-
std::vector<std::string> split = absl::StrSplit(key, kDelimiter);
24+
absl::StatusOr<RedisDbKey> GetRedisDbKey(const std::string& key,
25+
const std::string& delimiter) {
26+
std::vector<std::string> split = absl::StrSplit(key, delimiter);
2727

2828
// If there is no ':' character then the key is incorrectly formatted for our
2929
// use case.
3030
if (split.size() == 1) {
3131
return absl::Status(
3232
absl::StatusCode::kInvalidArgument,
33-
absl::StrCat("Key does not have a '", kDelimiter, "': ", key));
33+
absl::StrCat("Key does not have a '", delimiter, "': ", key));
3434
}
3535
return RedisDbKey{
3636
.table_name = split[0],
37-
.key = absl::StrJoin(split.begin() + 1, split.end(), kDelimiter)};
37+
.key = absl::StrJoin(split.begin() + 1, split.end(), delimiter)};
3838
}
3939

4040
} // namespace
@@ -80,7 +80,7 @@ std::unordered_map<std::string, std::string> FakeDBConnector::hgetall(
8080

8181
// If we get an invalid key we assume the entry does not exist and return
8282
// an empty map..
83-
auto redis_key = GetRedisDbKey(key);
83+
auto redis_key = GetRedisDbKey(key, delimiter_);
8484
if (!redis_key.ok()) {
8585
VLOG(1) << "WARNING: " << redis_key.status();
8686
return empty_map;
@@ -108,7 +108,7 @@ bool FakeDBConnector::exists(const std::string& key) {
108108

109109
// If we get an invalid key we assume the entry does not exist and return
110110
// false.
111-
auto redis_key = GetRedisDbKey(key);
111+
auto redis_key = GetRedisDbKey(key, delimiter_);
112112
if (!redis_key.ok()) {
113113
VLOG(1) << "WARNING: " << redis_key.status();
114114
return false;
@@ -132,7 +132,7 @@ int64_t FakeDBConnector::del(const std::string& key) {
132132
VLOG(1) << "Deleteing key: " << key;
133133

134134
// If we get an invalid key we assume the entry does not exist and return 0.
135-
auto redis_key = GetRedisDbKey(key);
135+
auto redis_key = GetRedisDbKey(key, delimiter_);
136136
if (!redis_key.ok()) {
137137
VLOG(1) << "WARNING: " << redis_key.status();
138138
return 0;
@@ -182,7 +182,7 @@ void FakeDBConnector::hmset(const std::string& key,
182182

183183
// If we get an invalid key then someone is formatting something wrong
184184
// internally. So just fail outright.
185-
auto redis_key = GetRedisDbKey(key);
185+
auto redis_key = GetRedisDbKey(key, delimiter_);
186186
if (!redis_key.ok()) {
187187
LOG(FATAL) << "Cannot fake inserting an invalid key: "
188188
<< redis_key.status();

tests/fakes/fake_db_connector.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace swss {
1616
// in a redis DB (e.g. AppDb, ConfigDb, AsicDb, etc.).
1717
class FakeDBConnector final : public DBConnectorInterface {
1818
public:
19-
FakeDBConnector() = default;
19+
explicit FakeDBConnector(const std::string& delimiter)
20+
: delimiter_(delimiter) {}
2021

2122
// Not copyable or moveable.
2223
FakeDBConnector(const FakeDBConnector&) = delete;
@@ -46,6 +47,9 @@ class FakeDBConnector final : public DBConnectorInterface {
4647
// val: faked table holding all installed entries.
4748
absl::flat_hash_map<std::string, FakeSonicDbTable*>
4849
sonic_db_tables_; // No ownership.
50+
51+
// Depending on the SONiC database the delimiter can either be a ":" or a "|".
52+
std::string delimiter_;
4953
};
5054

5155
} // namespace swss

0 commit comments

Comments
 (0)