Skip to content

Commit 5c86377

Browse files
committed
Improve coverage
Signed-off-by: Stephen Sun <[email protected]>
1 parent 7b2e678 commit 5c86377

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

tests/mock_tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ tests_SOURCES = aclorch_ut.cpp \
7878
mock_dash_orch_test.cpp \
7979
zmq_orch_ut.cpp \
8080
mock_saihelper.cpp \
81+
mirrororch_ut.cpp \
8182
$(top_srcdir)/warmrestart/warmRestartHelper.cpp \
8283
$(top_srcdir)/lib/gearboxutils.cpp \
8384
$(top_srcdir)/lib/subintf.cpp \

tests/mock_tests/mirrororch_ut.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Make selected privates visible for unit testing
2+
#define private public
3+
#include "directory.h"
4+
#undef private
5+
6+
#define protected public
7+
#include "orch.h"
8+
#undef protected
9+
10+
#define private public
11+
#include "switchorch.h"
12+
#undef private
13+
14+
#include "portsorch.h"
15+
#define private public
16+
#include "mirrororch.h"
17+
#undef private
18+
#include "mock_orch_test.h"
19+
20+
namespace mirrororch_test
21+
{
22+
using namespace mock_orch_test;
23+
24+
class MirrorOrchTest : public MockOrchTest
25+
{
26+
};
27+
28+
TEST_F(MirrorOrchTest, RejectsIngressWhenUnsupported)
29+
{
30+
// Ensure environment initialized by MockOrchTest
31+
ASSERT_NE(gSwitchOrch, nullptr);
32+
ASSERT_NE(gMirrorOrch, nullptr);
33+
34+
// Force ingress unsupported and egress supported
35+
gSwitchOrch->m_portIngressMirrorSupported = false;
36+
gSwitchOrch->m_portEgressMirrorSupported = true;
37+
38+
Port dummyPort; // Unused due to early return
39+
auto ret = gMirrorOrch->setUnsetPortMirror(dummyPort, /*ingress*/ true, /*set*/ true, /*sessionId*/ SAI_NULL_OBJECT_ID);
40+
ASSERT_FALSE(ret);
41+
}
42+
43+
TEST_F(MirrorOrchTest, RejectsEgressWhenUnsupported)
44+
{
45+
ASSERT_NE(gSwitchOrch, nullptr);
46+
ASSERT_NE(gMirrorOrch, nullptr);
47+
48+
// Force egress unsupported and ingress supported
49+
gSwitchOrch->m_portIngressMirrorSupported = true;
50+
gSwitchOrch->m_portEgressMirrorSupported = false;
51+
52+
Port dummyPort; // Unused due to early return
53+
auto ret = gMirrorOrch->setUnsetPortMirror(dummyPort, /*ingress*/ false, /*set*/ true, /*sessionId*/ SAI_NULL_OBJECT_ID);
54+
ASSERT_FALSE(ret);
55+
}
56+
}
57+

0 commit comments

Comments
 (0)