rings: RingOnePrefix()/RingOneAddress()
Ring one designates the (virtual) local network of a zone within a region. Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
package rings
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRingOneAddress(t *testing.T) {
|
||||
RZNTest(t, "RingOneAddress", RingOneAddress, []RZNTestCase{
|
||||
{1, 1, 50, MustParseAddr("10.1.16.50")},
|
||||
{1, 2, 50, MustParseAddr("10.1.32.50")},
|
||||
{2, 3, 300, MustParseAddr("10.2.49.44")},
|
||||
{1, 20, 50, netip.Addr{}},
|
||||
})
|
||||
}
|
||||
|
||||
type RZNTestCase struct {
|
||||
region RegionID
|
||||
zone ZoneID
|
||||
node NodeID
|
||||
addr netip.Addr
|
||||
}
|
||||
|
||||
func RZNTest(t *testing.T,
|
||||
fnName string, fn func(RegionID, ZoneID, NodeID) (netip.Addr, error),
|
||||
cases []RZNTestCase) {
|
||||
//
|
||||
for i, tc := range cases {
|
||||
s := fmt.Sprintf("%s(%v, %v, %v)", fnName,
|
||||
tc.region,
|
||||
tc.zone,
|
||||
tc.node,
|
||||
)
|
||||
|
||||
addr, err := fn(tc.region, tc.zone, tc.node)
|
||||
|
||||
switch {
|
||||
case !tc.addr.IsValid():
|
||||
// expect error
|
||||
if err != nil {
|
||||
t.Logf("[%v/%v]: %s → %s", i, len(cases), s, err)
|
||||
} else {
|
||||
t.Errorf("ERROR: [%v/%v]: %s → %s (expected %s)", i, len(cases), s, addr, "error")
|
||||
}
|
||||
case err != nil:
|
||||
t.Errorf("ERROR: [%v/%v]: %s → %s (expected %s)", i, len(cases), s, err, tc.addr)
|
||||
case addr.Compare(tc.addr) != 0:
|
||||
t.Errorf("ERROR: [%v/%v]: %s → %s (expected %s)", i, len(cases), s, addr, tc.addr)
|
||||
default:
|
||||
t.Logf("[%v/%v]: %s → %s", i, len(cases), s, addr)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user