Skip to content

Commit

Permalink
[#356] netmap: Increase test coverage of IterateSubnets
Browse files Browse the repository at this point in the history
Add both `False` and `True` subnet attributes.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
Leonard Lyubich authored and cthulhu-rider committed Nov 24, 2021
1 parent dfb780a commit 896cee4
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions netmap/attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

const (
numEntry = 13
numExit = 14
)

attr.SetKey(subnetAttrKey("13"))
attr.SetValue("True")
attrEntry.SetKey(subnetAttrKey(strconv.FormatUint(numEntry, 10)))
attrEntry.SetValue("True")

attrs := []*netmap.Attribute{&attr}
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) {
Expand Down

0 comments on commit 896cee4

Please sign in to comment.