Fix vendor regression in dhcp4server
This commit is contained in:
51
vendor/github.com/d2g/dhcp4server/leasepool/lease_test.go
generated
vendored
Normal file
51
vendor/github.com/d2g/dhcp4server/leasepool/lease_test.go
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
package leasepool
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
* The Leases are Marshalled and Unmarshalled for storage.
|
||||
* I JSON Marshal these for gvklite
|
||||
*/
|
||||
func TestMarshaling(test *testing.T) {
|
||||
var err error
|
||||
|
||||
startLease := Lease{}
|
||||
startLease.IP = net.IPv4(192, 168, 0, 1)
|
||||
startLease.Hostname = "ExampleHostname"
|
||||
startLease.Status = Active
|
||||
startLease.Expiry = time.Now()
|
||||
startLease.MACAddress, err = net.ParseMAC("01:23:45:67:89:ab")
|
||||
if err != nil {
|
||||
test.Error("Error Parsing Mac Address:" + err.Error())
|
||||
}
|
||||
|
||||
byteStartLease, err := json.Marshal(startLease)
|
||||
if err != nil {
|
||||
test.Error("Error Marshaling to JSON:" + err.Error())
|
||||
}
|
||||
|
||||
test.Log("StartLease As JSON:" + string(byteStartLease))
|
||||
|
||||
endLease := Lease{}
|
||||
err = json.Unmarshal(byteStartLease, &endLease)
|
||||
if err != nil {
|
||||
test.Error("Error Unmarshaling to JSON:" + err.Error())
|
||||
}
|
||||
|
||||
test.Logf("End Lease Object:%v\n", endLease)
|
||||
|
||||
if !startLease.Equal(endLease) {
|
||||
byteEndLease, err := json.Marshal(endLease)
|
||||
if err != nil {
|
||||
test.Error("Can't Marshal End Lease For Debuging:" + err.Error())
|
||||
}
|
||||
test.Log("End Lease as JSON:" + string(byteEndLease))
|
||||
test.Error("Starting Lease Doesn't Match End Lease")
|
||||
}
|
||||
|
||||
}
|
2
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool.go
generated
vendored
2
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool.go
generated
vendored
@ -104,7 +104,7 @@ func (t *MemoryPool) GetNextFreeLease() (bool, leasepool.Lease, error) {
|
||||
defer t.poolLock.Unlock()
|
||||
|
||||
//Loop Through the elements backwards.
|
||||
for i := (len(t.pool) - 1); i > 0; i-- {
|
||||
for i := (len(t.pool) - 1); i >= 0; i-- {
|
||||
//If the Lease Is Free
|
||||
if t.pool[i].Status == leasepool.Free {
|
||||
//Take the Element
|
||||
|
56
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool_test.go
generated
vendored
Normal file
56
vendor/github.com/d2g/dhcp4server/leasepool/memorypool/memorypool_test.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
package memorypool
|
||||
|
||||
import (
|
||||
"github.com/d2g/dhcp4"
|
||||
"github.com/d2g/dhcp4server/leasepool"
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLeaseCycle(test *testing.T) {
|
||||
myMemoryLeasePool := MemoryPool{}
|
||||
|
||||
//Lets add a list of IPs to the pool these will be served to the clients so make sure they work for you.
|
||||
// So Create Array of IPs 192.168.1.1 to 192.168.1.30
|
||||
for i := 0; i < 30; i++ {
|
||||
err := myMemoryLeasePool.AddLease(leasepool.Lease{IP: dhcp4.IPAdd(net.IPv4(192, 168, 1, 1), i)})
|
||||
if err != nil {
|
||||
test.Error("Error Creating Lease:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
hasLease, iLease, err := myMemoryLeasePool.GetNextFreeLease()
|
||||
if err != nil {
|
||||
test.Error("Error Getting Lease:" + err.Error())
|
||||
}
|
||||
if !hasLease {
|
||||
test.Error("Failed to get get lease (none free?)")
|
||||
}
|
||||
|
||||
if !dhcp4.IPAdd(net.IPv4(192, 168, 1, 1), i).Equal(iLease.IP) {
|
||||
test.Error("Expected Lease:" + dhcp4.IPAdd(net.IPv4(192, 168, 1, 1), i).String() + " Received:" + iLease.IP.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSingleLease(test *testing.T) {
|
||||
myMemoryLeasePool := MemoryPool{}
|
||||
|
||||
err := myMemoryLeasePool.AddLease(leasepool.Lease{IP: dhcp4.IPAdd(net.IPv4(192, 168, 1, 5), 0)})
|
||||
if err != nil {
|
||||
test.Error("Error Creating Lease:" + err.Error())
|
||||
}
|
||||
|
||||
hasLease, iLease, err := myMemoryLeasePool.GetNextFreeLease()
|
||||
if err != nil {
|
||||
test.Error("Error Getting Lease:" + err.Error())
|
||||
}
|
||||
if !hasLease {
|
||||
test.Error("Failed to get get lease (none free?)")
|
||||
}
|
||||
|
||||
if !dhcp4.IPAdd(net.IPv4(192, 168, 1, 5), 0).Equal(iLease.IP) {
|
||||
test.Error("Expected Lease:" + dhcp4.IPAdd(net.IPv4(192, 168, 1, 5), 0).String() + " Received:" + iLease.IP.String())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user