From 896cee4bb0ae491663362dd3d3ca8180cd959a0e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 22 Nov 2021 14:02:52 +0300 Subject: [PATCH] [#356] netmap: Increase test coverage of IterateSubnets Add both `False` and `True` subnet attributes. Signed-off-by: Leonard Lyubich --- netmap/attributes_test.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/netmap/attributes_test.go b/netmap/attributes_test.go index f282c86..93586ac 100644 --- a/netmap/attributes_test.go +++ b/netmap/attributes_test.go @@ -113,29 +113,44 @@ func TestSubnets(t *testing.T) { t.Run("with correct attribute", func(t *testing.T) { var ( node netmap.NodeInfo - attr netmap.Attribute + + attrEntry, attrExit netmap.Attribute ) - attr.SetKey(subnetAttrKey("13")) - attr.SetValue("True") + const ( + numEntry = 13 + numExit = 14 + ) - attrs := []*netmap.Attribute{&attr} + attrEntry.SetKey(subnetAttrKey(strconv.FormatUint(numEntry, 10))) + attrEntry.SetValue("True") + + attrExit.SetKey(subnetAttrKey(strconv.FormatUint(numExit, 10))) + attrExit.SetValue("False") + + attrs := []*netmap.Attribute{&attrEntry, &attrEntry} node.SetAttributes(attrs) - called := 0 + mCalledNums := make(map[uint32]struct{}) err := netmap.IterateSubnets(&node, func(id refs.SubnetID) error { - if !refs.IsZeroSubnet(&id) { - called++ - require.EqualValues(t, 13, id.GetValue()) - } + mCalledNums[id.GetValue()] = struct{}{} return nil }) require.NoError(t, err) - require.EqualValues(t, 1, called) + require.Len(t, mCalledNums, 2) + + _, ok := mCalledNums[numEntry] + require.True(t, ok) + + _, ok = mCalledNums[numExit] + require.False(t, ok) + + _, ok = mCalledNums[0] + require.True(t, ok) }) t.Run("with incorrect attribute", func(t *testing.T) {