blob: ab2921546170b3299d5118cc7aed7df3734db2f5 [file] [log] [blame]
Ratan Gupta1dc91782018-04-19 16:47:12 +05301#include "snmp_conf_manager.hpp"
2
3#include "xyz/openbmc_project/Common/error.hpp"
4
5#include <gtest/gtest.h>
6#include <sdbusplus/bus.hpp>
7
8namespace phosphor
9{
10namespace network
11{
12namespace snmp
13{
14
15class TestSNMPConfManager : public testing::Test
16{
17 public:
18 sdbusplus::bus::bus bus;
19 ConfManager manager;
20 std::string confDir;
21 TestSNMPConfManager() :
22 bus(sdbusplus::bus::new_default()), manager(bus, ""){};
23
24 ~TestSNMPConfManager()
25 {
26 }
27
28 void createSNMPClient(std::string ipaddress, uint16_t port)
29 {
30 manager.client(ipaddress, port);
31 }
32
33 ClientList &getSNMPClients()
34 {
35 return manager.clients;
36 }
37
38 void deleteSNMPClient(std::string ipaddress)
39 {
40 if (manager.clients.find(ipaddress) != manager.clients.end())
41 {
42 auto &it = manager.clients[ipaddress];
43 it->delete_();
44 }
45 }
46};
47
48// Add single SNMP client
49TEST_F(TestSNMPConfManager, AddSNMPClient)
50{
51 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
52
53 createSNMPClient("192.168.1.1", 24);
54
55 auto &clients = getSNMPClients();
56 EXPECT_EQ(1, clients.size());
57 EXPECT_EQ(true, clients.find("192.168.1.1") != clients.end());
58}
59
60// Add multiple SNMP client
61TEST_F(TestSNMPConfManager, AddMultipleSNMPClient)
62{
63 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
64
65 createSNMPClient("192.168.1.1", 24);
66 createSNMPClient("192.168.1.2", 24);
67
68 auto &clients = getSNMPClients();
69 EXPECT_EQ(2, clients.size());
70 EXPECT_EQ(true, clients.find("192.168.1.1") != clients.end());
71 EXPECT_EQ(true, clients.find("192.168.1.2") != clients.end());
72}
73
74// Delete SNMP client
75TEST_F(TestSNMPConfManager, DeleteSNMPClient)
76{
77 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
78
79 createSNMPClient("192.168.1.1", 24);
80 createSNMPClient("192.168.1.2", 24);
81
82 auto &clients = getSNMPClients();
83 EXPECT_EQ(2, clients.size());
84 deleteSNMPClient("192.168.1.1");
85 EXPECT_EQ(1, clients.size());
86 EXPECT_EQ(true, clients.find("192.168.1.2") != clients.end());
87}
88
89} // namespace snmp
90} // namespce network
91} // namespace phosphor