1
1
#include " gtest/gtest.h"
2
2
#include < iostream>
3
- #include < fstream>
3
+ #include < fstream>
4
4
#include < unistd.h>
5
5
#include < sys/stat.h>
6
6
#include " ../mock_table.h"
@@ -20,29 +20,32 @@ int cb(const std::string &cmd, std::string &stdout){
20
20
else if (cmd.find (" /sbin/ip -6 address \" add\" " ) == 0 ) {
21
21
return Ethernet0IPv6Set ? 0 : 2 ;
22
22
}
23
+ else if (cmd == " /sbin/ip link set \" Ethernet64.10\" \" up\" " ){
24
+ return 1 ;
25
+ }
23
26
else {
24
27
return 0 ;
25
28
}
26
29
return 0 ;
27
30
}
28
31
29
32
// Test Fixture
30
- namespace add_ipv6_prefix_ut
33
+ namespace intfmgr_ut
31
34
{
32
35
struct IntfMgrTest : public ::testing::Test
33
36
{
34
37
std::shared_ptr<swss::DBConnector> m_config_db;
35
38
std::shared_ptr<swss::DBConnector> m_app_db;
36
39
std::shared_ptr<swss::DBConnector> m_state_db;
37
40
std::vector<std::string> cfg_intf_tables;
38
-
41
+
39
42
virtual void SetUp () override
40
- {
43
+ {
41
44
testing_db::reset ();
42
45
m_config_db = std::make_shared<swss::DBConnector>(" CONFIG_DB" , 0 );
43
46
m_app_db = std::make_shared<swss::DBConnector>(" APPL_DB" , 0 );
44
47
m_state_db = std::make_shared<swss::DBConnector>(" STATE_DB" , 0 );
45
-
48
+
46
49
swss::WarmStart::initialize (" intfmgrd" , " swss" );
47
50
48
51
std::vector<std::string> tables = {
@@ -106,4 +109,22 @@ namespace add_ipv6_prefix_ut
106
109
}
107
110
ASSERT_EQ (ip_cmd_called, 1 );
108
111
}
112
+
113
+ // This test except no runtime error when the set admin status command failed
114
+ // and the subinterface has not ok status (for example not existing subinterface)
115
+ TEST_F (IntfMgrTest, testSetAdminStatusFailToNotOkSubInt){
116
+ swss::IntfMgr intfmgr (m_config_db.get (), m_app_db.get (), m_state_db.get (), cfg_intf_tables);
117
+ intfmgr.setHostSubIntfAdminStatus (" Ethernet64.10" , " up" , " up" );
118
+ }
119
+
120
+ // This test except runtime error when the set admin status command failed
121
+ // and the subinterface has ok status
122
+ TEST_F (IntfMgrTest, testSetAdminStatusFailToOkSubInt){
123
+ swss::IntfMgr intfmgr (m_config_db.get (), m_app_db.get (), m_state_db.get (), cfg_intf_tables);
124
+ /* Set portStateTable */
125
+ std::vector<swss::FieldValueTuple> values;
126
+ values.emplace_back (" state" , " ok" );
127
+ intfmgr.m_statePortTable .set (" Ethernet64.10" , values, " SET" , " " );
128
+ EXPECT_THROW (intfmgr.setHostSubIntfAdminStatus (" Ethernet64.10" , " up" , " up" ), std::runtime_error);
129
+ }
109
130
}
0 commit comments