From 551cc5859efa7e290a5ada86aec2d53e41ab480d Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Mon, 20 Feb 2023 17:59:09 +0200 Subject: [PATCH] tests: Cover all enum values for unit tests Signed-off-by: Donatas Abraitis --- tests/bgpd/test_peer_attr.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/tests/bgpd/test_peer_attr.c b/tests/bgpd/test_peer_attr.c index 090fb9a9f9..652aaa25d4 100644 --- a/tests/bgpd/test_peer_attr.c +++ b/tests/bgpd/test_peer_attr.c @@ -650,21 +650,14 @@ static const char *str_from_afi(afi_t afi) return "ipv4"; case AFI_IP6: return "ipv6"; - default: - return ""; + case AFI_L2VPN: + return "l2vpn"; + case AFI_MAX: + case AFI_UNSPEC: + return "bad-value"; } -} -static const char *str_from_safi(safi_t safi) -{ - switch (safi) { - case SAFI_UNICAST: - return "unicast"; - case SAFI_MULTICAST: - return "multicast"; - default: - return ""; - } + assert(!"Reached end of function we should never reach"); } static const char *str_from_attr_type(enum test_peer_attr_type at) @@ -1150,7 +1143,7 @@ static void test_peer_attr(struct test *test, struct test_peer_attr *pa) test_log(test, "prepare: switch address-family to [%s]", get_afi_safi_str(pa->afi, pa->safi, false)); test_execute(test, "address-family %s %s", - str_from_afi(pa->afi), str_from_safi(pa->safi)); + str_from_afi(pa->afi), safi2str(pa->safi)); test_execute(test, "neighbor %s activate", g->name); test_execute(test, "neighbor %s activate", p->host); } @@ -1217,7 +1210,7 @@ static void test_peer_attr(struct test *test, struct test_peer_attr *pa) test_log(test, "prepare: switch address-family to [%s]", get_afi_safi_str(pa->afi, pa->safi, false)); test_execute(test, "address-family %s %s", - str_from_afi(pa->afi), str_from_safi(pa->safi)); + str_from_afi(pa->afi), safi2str(pa->safi)); test_execute(test, "neighbor %s activate", g->name); test_execute(test, "neighbor %s activate", p->host); } @@ -1265,7 +1258,7 @@ static void test_peer_attr(struct test *test, struct test_peer_attr *pa) test_log(test, "prepare: switch address-family to [%s]", get_afi_safi_str(pa->afi, pa->safi, false)); test_execute(test, "address-family %s %s", - str_from_afi(pa->afi), str_from_safi(pa->safi)); + str_from_afi(pa->afi), safi2str(pa->safi)); test_execute(test, "neighbor %s activate", g->name); test_execute(test, "neighbor %s activate", p->host); } @@ -1464,7 +1457,7 @@ int main(void) if (pa->afi && pa->safi) desc = asprintfrr(MTYPE_TMP, "peer\\%s-%s\\%s", str_from_afi(pa->afi), - str_from_safi(pa->safi), pa->cmd); + safi2str(pa->safi), pa->cmd); else desc = asprintfrr(MTYPE_TMP, "peer\\%s", pa->cmd); -- 2.39.5