moby/libnetwork/ipams/windowsipam/windowsipam_test.go
Sebastiaan van Stijn 427ad30c05
libnetwork: remove unused "testutils" imports
Perhaps the testutils package in the past had an `init()` function to set up
specific things, but it no longer has. so these imports were doing nothing.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-18 14:20:37 +02:00

83 lines
2.3 KiB
Go

package windowsipam
import (
"net"
"testing"
"github.com/docker/docker/libnetwork/ipamapi"
"github.com/docker/docker/libnetwork/netlabel"
"github.com/docker/docker/libnetwork/types"
)
func TestWindowsIPAM(t *testing.T) {
a := &allocator{}
requestPool, _ := types.ParseCIDR("192.168.0.0/16")
requestAddress := net.ParseIP("192.168.1.1")
pid, pool, _, err := a.RequestPool(localAddressSpace, "", "", nil, false)
if err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(defaultPool, pool) ||
pid != pool.String() {
t.Fatalf("Unexpected data returned. Expected %v : %s. Got: %v : %s", defaultPool, pid, pool, pool.String())
}
pid, pool, _, err = a.RequestPool(localAddressSpace, requestPool.String(), "", nil, false)
if err != nil {
t.Fatal(err)
}
if !types.CompareIPNet(requestPool, pool) ||
pid != requestPool.String() {
t.Fatalf("Unexpected data returned. Expected %v : %s. Got: %v : %s", requestPool, requestPool.String(), pool, pool.String())
}
_, _, _, err = a.RequestPool(localAddressSpace, requestPool.String(), requestPool.String(), nil, false)
if err == nil {
t.Fatal("Unexpected success for subpool request")
}
_, _, _, err = a.RequestPool(localAddressSpace, requestPool.String(), "", nil, true)
if err == nil {
t.Fatal("Unexpected success for v6 request")
}
err = a.ReleasePool(requestPool.String())
if err != nil {
t.Fatal(err)
}
ip, _, err := a.RequestAddress(requestPool.String(), nil, map[string]string{})
if err != nil {
t.Fatal(err)
}
if ip != nil {
t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestPool, ip)
}
ip, _, err = a.RequestAddress(requestPool.String(), requestAddress, map[string]string{})
if err != nil {
t.Fatal(err)
}
if !ip.IP.Equal(requestAddress) {
t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestAddress, ip.IP)
}
requestOptions := map[string]string{}
requestOptions[ipamapi.RequestAddressType] = netlabel.Gateway
ip, _, err = a.RequestAddress(requestPool.String(), requestAddress, requestOptions)
if err != nil {
t.Fatal(err)
}
if !ip.IP.Equal(requestAddress) {
t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestAddress, ip.IP)
}
err = a.ReleaseAddress(requestPool.String(), requestAddress)
if err != nil {
t.Fatal(err)
}
}