func TestRenewLease(t *testing.T) {
	msr := newMockSubnetRegistry(1)
	sm, err := newSubnetManager(msr)
	if err != nil {
		t.Fatalf("Failed to create subnet manager: %s", err)
	}

	ip, _ := ip.ParseIP4("1.2.3.4")
	data := `{ "PublicIP": "1.2.3.4" }`

	sn, err := sm.AcquireLease(ip, data)
	if err != nil {
		t.Fatal("AcquireLease failed: ", err)
	}

	events := make(chan EventBatch)
	sm.Start(events)

	fmt.Println("Waiting for lease to pass original expiration")
	time.Sleep(2 * time.Second)

	// check that it's still good
	for _, n := range msr.subnets.Nodes {
		if n.Key == sn.StringSep(".", "-") {
			if n.Expiration.Before(time.Now()) {
				t.Fatalf("Failed to renew lease")
			}
			return
		}
	}

	t.Fatalf("Failed to find acquired lease")
}
func TestAcquireLease(t *testing.T) {
	msr := newMockSubnetRegistry(0)
	sm, err := newSubnetManager(msr)
	if err != nil {
		t.Fatalf("Failed to create subnet manager: %s", err)
	}

	ip, _ := ip.ParseIP4("1.2.3.4")
	data := `{ "PublicIP": "1.2.3.4" }`

	sn, err := sm.AcquireLease(ip, data)
	if err != nil {
		t.Fatal("AcquireLease failed: ", err)
	}

	if sn.String() != "10.3.3.0/24" {
		t.Fatal("Subnet mismatch: expected 10.3.3.0/24, got: ", sn)
	}

	// Acquire again, should reuse
	if sn, err = sm.AcquireLease(ip, data); err != nil {
		t.Fatal("AcquireLease failed: ", err)
	}

	if sn.String() != "10.3.3.0/24" {
		t.Fatal("Subnet mismatch: expected 10.3.3.0/24, got: ", sn)
	}
}