-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UT coverage to 95%, code improve and minor fix (#34)
* global mock, ut coverage to 95%, code cleanup and refine
- Loading branch information
Showing
19 changed files
with
356 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "gmock_global"] | ||
path = gmock_global | ||
url = https://github.com/apriorit/gmock-global.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule gmock_global
added at
6552fa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
SRCS += \ | ||
src/sender.cpp \ | ||
src/relay.cpp \ | ||
src/configInterface.cpp \ | ||
src/config_interface.cpp \ | ||
src/main.cpp |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "mock_config_interface.h" | ||
|
||
using namespace ::testing; | ||
|
||
TEST(configInterface, initialize_swss) { | ||
std::shared_ptr<swss::DBConnector> config_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_servers@", "fc02:2000::1,fc02:2000::2,fc02:2000::3,fc02:2000::4"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|rfc6939_support", "false"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|interface_id", "true"); | ||
std::unordered_map<std::string, relay_config> vlans; | ||
ASSERT_NO_THROW(initialize_swss(vlans)); | ||
EXPECT_EQ(vlans.size(), 1); | ||
} | ||
|
||
TEST(configInterface, deinitialize_swss) { | ||
ASSERT_NO_THROW(deinitialize_swss()); | ||
} | ||
|
||
TEST(configInterface, get_dhcp) { | ||
std::shared_ptr<swss::DBConnector> config_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_servers@", "fc02:2000::1,fc02:2000::2,fc02:2000::3,fc02:2000::4"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|rfc6939_support", "false"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|interface_id", "true"); | ||
swss::SubscriberStateTable ipHelpersTable(config_db.get(), "DHCP_RELAY"); | ||
std::unordered_map<std::string, relay_config> vlans; | ||
|
||
ASSERT_NO_THROW(get_dhcp(vlans, &ipHelpersTable, false)); | ||
EXPECT_EQ(vlans.size(), 0); | ||
|
||
swssSelect.addSelectable(&ipHelpersTable); | ||
|
||
ASSERT_NO_THROW(get_dhcp(vlans, &ipHelpersTable, false)); | ||
EXPECT_EQ(vlans.size(), 1); | ||
} | ||
|
||
TEST(configInterface, handleRelayNotification) { | ||
std::shared_ptr<swss::DBConnector> cfg_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
swss::SubscriberStateTable ipHelpersTable(cfg_db.get(), "DHCP_RELAY"); | ||
std::unordered_map<std::string, relay_config> vlans; | ||
handleRelayNotification(ipHelpersTable, vlans); | ||
} | ||
|
||
TEST(configInterface, processRelayNotification) { | ||
std::shared_ptr<swss::DBConnector> config_db = std::make_shared<swss::DBConnector> ("CONFIG_DB", 0); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_servers@", "fc02:2000::1,fc02:2000::2,fc02:2000::3,fc02:2000::4"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|rfc6939_support", "false"); | ||
config_db->hset("DHCP_RELAY|Vlan1000", "dhcpv6_option|interface_id", "true"); | ||
swss::SubscriberStateTable ipHelpersTable(config_db.get(), "DHCP_RELAY"); | ||
swssSelect.addSelectable(&ipHelpersTable); | ||
std::deque<swss::KeyOpFieldsValuesTuple> entries; | ||
ipHelpersTable.pops(entries); | ||
std::unordered_map<std::string, relay_config> vlans; | ||
|
||
processRelayNotification(entries, vlans); | ||
|
||
EXPECT_EQ(vlans.size(), 1); | ||
EXPECT_FALSE(vlans["Vlan1000"].is_option_79); | ||
EXPECT_TRUE(vlans["Vlan1000"].is_interface_id); | ||
EXPECT_FALSE(vlans["Vlan1000"].state_db); | ||
} | ||
|
||
MOCK_GLOBAL_FUNC0(stopSwssNotificationPoll, void(void)); | ||
|
||
TEST(configInterface, stopSwssNotificationPoll) { | ||
EXPECT_GLOBAL_CALL(stopSwssNotificationPoll, stopSwssNotificationPoll()).Times(1); | ||
ASSERT_NO_THROW(stopSwssNotificationPoll()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "../src/config_interface.h" | ||
#include "mock_send.h" | ||
#include "gmock/gmock.h" | ||
#include "gtest/gtest.h" | ||
#include "../gmock_global/include/gmock-global/gmock-global.h" | ||
#include <new> | ||
#include <future> | ||
|
||
extern bool pollSwssNotifcation; | ||
extern swss::Select swssSelect; |
Oops, something went wrong.