libn/cnmallocator: migrate tests to gotest.tools/v3

Apply command gotest.tools/v3/assert/cmd/gty-migrate-from-testify to the
cnmallocator package to be consistent with the assertion library used
elsewhere in moby.

Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
Cory Snider 2024-02-29 16:10:31 -05:00
parent 7b0ab1011c
commit 4f30a930ad
3 changed files with 166 additions and 164 deletions

View file

@ -8,13 +8,14 @@ import (
"github.com/docker/docker/libnetwork/types"
"github.com/moby/swarmkit/v2/api"
"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func newNetworkAllocator(t *testing.T) networkallocator.NetworkAllocator {
na, err := (&Provider{}).NewAllocator(nil)
assert.NoError(t, err)
assert.NotNil(t, na)
assert.Check(t, err)
assert.Check(t, na != nil)
return na
}
@ -39,7 +40,7 @@ func TestAllocateInvalidIPAM(t *testing.T) {
},
}
err := na.Allocate(n)
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
}
func TestAllocateInvalidDriver(t *testing.T) {
@ -57,7 +58,7 @@ func TestAllocateInvalidDriver(t *testing.T) {
}
err := na.Allocate(n)
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
}
func TestNetworkDoubleAllocate(t *testing.T) {
@ -72,10 +73,10 @@ func TestNetworkDoubleAllocate(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Check(t, err)
err = na.Allocate(n)
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
}
func TestAllocateEmptyConfig(t *testing.T) {
@ -100,60 +101,60 @@ func TestAllocateEmptyConfig(t *testing.T) {
}
err := na1.Allocate(n1)
assert.NoError(t, err)
assert.NotEqual(t, n1.IPAM.Configs, nil)
assert.Equal(t, len(n1.IPAM.Configs), 1)
assert.Equal(t, n1.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n1.IPAM.Configs[0].Reserved), 0)
assert.Check(t, err)
assert.Check(t, n1.IPAM.Configs != nil)
assert.Check(t, is.Equal(len(n1.IPAM.Configs), 1))
assert.Check(t, is.Equal(n1.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n1.IPAM.Configs[0].Reserved), 0))
_, subnet11, err := net.ParseCIDR(n1.IPAM.Configs[0].Subnet)
assert.NoError(t, err)
assert.Check(t, err)
gwip11 := net.ParseIP(n1.IPAM.Configs[0].Gateway)
assert.NotEqual(t, gwip11, nil)
assert.Check(t, gwip11 != nil)
err = na1.Allocate(n2)
assert.NoError(t, err)
assert.NotEqual(t, n2.IPAM.Configs, nil)
assert.Equal(t, len(n2.IPAM.Configs), 1)
assert.Equal(t, n2.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n2.IPAM.Configs[0].Reserved), 0)
assert.Check(t, err)
assert.Check(t, n2.IPAM.Configs != nil)
assert.Check(t, is.Equal(len(n2.IPAM.Configs), 1))
assert.Check(t, is.Equal(n2.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n2.IPAM.Configs[0].Reserved), 0))
_, subnet21, err := net.ParseCIDR(n2.IPAM.Configs[0].Subnet)
assert.NoError(t, err)
assert.Check(t, err)
gwip21 := net.ParseIP(n2.IPAM.Configs[0].Gateway)
assert.NotEqual(t, gwip21, nil)
assert.Check(t, gwip21 != nil)
// Allocate n1 ans n2 with another allocator instance but in
// intentionally reverse order.
err = na2.Allocate(n2)
assert.NoError(t, err)
assert.NotEqual(t, n2.IPAM.Configs, nil)
assert.Equal(t, len(n2.IPAM.Configs), 1)
assert.Equal(t, n2.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n2.IPAM.Configs[0].Reserved), 0)
assert.Check(t, err)
assert.Check(t, n2.IPAM.Configs != nil)
assert.Check(t, is.Equal(len(n2.IPAM.Configs), 1))
assert.Check(t, is.Equal(n2.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n2.IPAM.Configs[0].Reserved), 0))
_, subnet22, err := net.ParseCIDR(n2.IPAM.Configs[0].Subnet)
assert.NoError(t, err)
assert.Equal(t, subnet21, subnet22)
assert.Check(t, err)
assert.Check(t, is.DeepEqual(subnet21, subnet22))
gwip22 := net.ParseIP(n2.IPAM.Configs[0].Gateway)
assert.Equal(t, gwip21, gwip22)
assert.Check(t, is.DeepEqual(gwip21, gwip22))
err = na2.Allocate(n1)
assert.NoError(t, err)
assert.NotEqual(t, n1.IPAM.Configs, nil)
assert.Equal(t, len(n1.IPAM.Configs), 1)
assert.Equal(t, n1.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n1.IPAM.Configs[0].Reserved), 0)
assert.Check(t, err)
assert.Check(t, n1.IPAM.Configs != nil)
assert.Check(t, is.Equal(len(n1.IPAM.Configs), 1))
assert.Check(t, is.Equal(n1.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n1.IPAM.Configs[0].Reserved), 0))
_, subnet12, err := net.ParseCIDR(n1.IPAM.Configs[0].Subnet)
assert.NoError(t, err)
assert.Equal(t, subnet11, subnet12)
assert.Check(t, err)
assert.Check(t, is.DeepEqual(subnet11, subnet12))
gwip12 := net.ParseIP(n1.IPAM.Configs[0].Gateway)
assert.Equal(t, gwip11, gwip12)
assert.Check(t, is.DeepEqual(gwip11, gwip12))
}
func TestAllocateWithOneSubnet(t *testing.T) {
@ -177,14 +178,14 @@ func TestAllocateWithOneSubnet(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Equal(t, len(n.IPAM.Configs), 1)
assert.Equal(t, n.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n.IPAM.Configs[0].Reserved), 0)
assert.Equal(t, n.IPAM.Configs[0].Subnet, "192.168.1.0/24")
assert.Check(t, err)
assert.Check(t, is.Equal(len(n.IPAM.Configs), 1))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n.IPAM.Configs[0].Reserved), 0))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Subnet, "192.168.1.0/24"))
ip := net.ParseIP(n.IPAM.Configs[0].Gateway)
assert.NotEqual(t, ip, nil)
assert.Check(t, ip != nil)
}
func TestAllocateWithOneSubnetGateway(t *testing.T) {
@ -209,12 +210,12 @@ func TestAllocateWithOneSubnetGateway(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Equal(t, len(n.IPAM.Configs), 1)
assert.Equal(t, n.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n.IPAM.Configs[0].Reserved), 0)
assert.Equal(t, n.IPAM.Configs[0].Subnet, "192.168.1.0/24")
assert.Equal(t, n.IPAM.Configs[0].Gateway, "192.168.1.1")
assert.Check(t, err)
assert.Check(t, is.Equal(len(n.IPAM.Configs), 1))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n.IPAM.Configs[0].Reserved), 0))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Subnet, "192.168.1.0/24"))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Gateway, "192.168.1.1"))
}
func TestAllocateWithOneSubnetInvalidGateway(t *testing.T) {
@ -239,7 +240,7 @@ func TestAllocateWithOneSubnetInvalidGateway(t *testing.T) {
}
err := na.Allocate(n)
assert.Error(t, err)
assert.Check(t, is.ErrorContains(err, ""))
}
// TestAllocateWithSmallSubnet validates that /32 subnets don't produce an error,
@ -266,7 +267,7 @@ func TestAllocateWithSmallSubnet(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Check(t, err)
}
func TestAllocateWithTwoSubnetsNoGateway(t *testing.T) {
@ -293,19 +294,19 @@ func TestAllocateWithTwoSubnetsNoGateway(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Equal(t, len(n.IPAM.Configs), 2)
assert.Equal(t, n.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n.IPAM.Configs[0].Reserved), 0)
assert.Equal(t, n.IPAM.Configs[0].Subnet, "192.168.1.0/24")
assert.Equal(t, n.IPAM.Configs[1].Range, "")
assert.Equal(t, len(n.IPAM.Configs[1].Reserved), 0)
assert.Equal(t, n.IPAM.Configs[1].Subnet, "192.168.2.0/24")
assert.Check(t, err)
assert.Check(t, is.Equal(len(n.IPAM.Configs), 2))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n.IPAM.Configs[0].Reserved), 0))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Subnet, "192.168.1.0/24"))
assert.Check(t, is.Equal(n.IPAM.Configs[1].Range, ""))
assert.Check(t, is.Equal(len(n.IPAM.Configs[1].Reserved), 0))
assert.Check(t, is.Equal(n.IPAM.Configs[1].Subnet, "192.168.2.0/24"))
ip := net.ParseIP(n.IPAM.Configs[0].Gateway)
assert.NotEqual(t, ip, nil)
assert.Check(t, ip != nil)
ip = net.ParseIP(n.IPAM.Configs[1].Gateway)
assert.NotEqual(t, ip, nil)
assert.Check(t, ip != nil)
}
func TestFree(t *testing.T) {
@ -330,14 +331,14 @@ func TestFree(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Check(t, err)
err = na.Deallocate(n)
assert.NoError(t, err)
assert.Check(t, err)
// Reallocate again to make sure it succeeds.
err = na.Allocate(n)
assert.NoError(t, err)
assert.Check(t, err)
}
func TestAllocateTaskFree(t *testing.T) {
@ -404,112 +405,112 @@ func TestAllocateTaskFree(t *testing.T) {
}
err := na1.Allocate(n1)
assert.NoError(t, err)
assert.Check(t, err)
err = na1.Allocate(n2)
assert.NoError(t, err)
assert.Check(t, err)
err = na1.AllocateTask(task1)
assert.NoError(t, err)
assert.Equal(t, len(task1.Networks[0].Addresses), 1)
assert.Equal(t, len(task1.Networks[1].Addresses), 1)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task1.Networks[0].Addresses), 1))
assert.Check(t, is.Equal(len(task1.Networks[1].Addresses), 1))
_, subnet1, _ := net.ParseCIDR("192.168.1.0/24")
_, subnet2, _ := net.ParseCIDR("192.168.2.0/24")
// variable coding: network/task/allocator
ip111, _, err := net.ParseCIDR(task1.Networks[0].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
ip211, _, err := net.ParseCIDR(task1.Networks[1].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, subnet1.Contains(ip111), true)
assert.Equal(t, subnet2.Contains(ip211), true)
assert.Check(t, is.Equal(subnet1.Contains(ip111), true))
assert.Check(t, is.Equal(subnet2.Contains(ip211), true))
err = na1.AllocateTask(task2)
assert.NoError(t, err)
assert.Equal(t, len(task2.Networks[0].Addresses), 1)
assert.Equal(t, len(task2.Networks[1].Addresses), 1)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task2.Networks[0].Addresses), 1))
assert.Check(t, is.Equal(len(task2.Networks[1].Addresses), 1))
ip121, _, err := net.ParseCIDR(task2.Networks[0].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
ip221, _, err := net.ParseCIDR(task2.Networks[1].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, subnet1.Contains(ip121), true)
assert.Equal(t, subnet2.Contains(ip221), true)
assert.Check(t, is.Equal(subnet1.Contains(ip121), true))
assert.Check(t, is.Equal(subnet2.Contains(ip221), true))
// Now allocate the same the same tasks in a second allocator
// but intentionally in reverse order.
err = na2.Allocate(n1)
assert.NoError(t, err)
assert.Check(t, err)
err = na2.Allocate(n2)
assert.NoError(t, err)
assert.Check(t, err)
err = na2.AllocateTask(task2)
assert.NoError(t, err)
assert.Equal(t, len(task2.Networks[0].Addresses), 1)
assert.Equal(t, len(task2.Networks[1].Addresses), 1)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task2.Networks[0].Addresses), 1))
assert.Check(t, is.Equal(len(task2.Networks[1].Addresses), 1))
ip122, _, err := net.ParseCIDR(task2.Networks[0].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
ip222, _, err := net.ParseCIDR(task2.Networks[1].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, subnet1.Contains(ip122), true)
assert.Equal(t, subnet2.Contains(ip222), true)
assert.Equal(t, ip121, ip122)
assert.Equal(t, ip221, ip222)
assert.Check(t, is.Equal(subnet1.Contains(ip122), true))
assert.Check(t, is.Equal(subnet2.Contains(ip222), true))
assert.Check(t, is.DeepEqual(ip121, ip122))
assert.Check(t, is.DeepEqual(ip221, ip222))
err = na2.AllocateTask(task1)
assert.NoError(t, err)
assert.Equal(t, len(task1.Networks[0].Addresses), 1)
assert.Equal(t, len(task1.Networks[1].Addresses), 1)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task1.Networks[0].Addresses), 1))
assert.Check(t, is.Equal(len(task1.Networks[1].Addresses), 1))
ip112, _, err := net.ParseCIDR(task1.Networks[0].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
ip212, _, err := net.ParseCIDR(task1.Networks[1].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, subnet1.Contains(ip112), true)
assert.Equal(t, subnet2.Contains(ip212), true)
assert.Equal(t, ip111, ip112)
assert.Equal(t, ip211, ip212)
assert.Check(t, is.Equal(subnet1.Contains(ip112), true))
assert.Check(t, is.Equal(subnet2.Contains(ip212), true))
assert.Check(t, is.DeepEqual(ip111, ip112))
assert.Check(t, is.DeepEqual(ip211, ip212))
// Deallocate task
err = na1.DeallocateTask(task1)
assert.NoError(t, err)
assert.Equal(t, len(task1.Networks[0].Addresses), 0)
assert.Equal(t, len(task1.Networks[1].Addresses), 0)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task1.Networks[0].Addresses), 0))
assert.Check(t, is.Equal(len(task1.Networks[1].Addresses), 0))
// Try allocation after free
err = na1.AllocateTask(task1)
assert.NoError(t, err)
assert.Equal(t, len(task1.Networks[0].Addresses), 1)
assert.Equal(t, len(task1.Networks[1].Addresses), 1)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task1.Networks[0].Addresses), 1))
assert.Check(t, is.Equal(len(task1.Networks[1].Addresses), 1))
ip111, _, err = net.ParseCIDR(task1.Networks[0].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
ip211, _, err = net.ParseCIDR(task1.Networks[1].Addresses[0])
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, subnet1.Contains(ip111), true)
assert.Equal(t, subnet2.Contains(ip211), true)
assert.Check(t, is.Equal(subnet1.Contains(ip111), true))
assert.Check(t, is.Equal(subnet2.Contains(ip211), true))
err = na1.DeallocateTask(task1)
assert.NoError(t, err)
assert.Equal(t, len(task1.Networks[0].Addresses), 0)
assert.Equal(t, len(task1.Networks[1].Addresses), 0)
assert.Check(t, err)
assert.Check(t, is.Equal(len(task1.Networks[0].Addresses), 0))
assert.Check(t, is.Equal(len(task1.Networks[1].Addresses), 0))
// Try to free endpoints on an already freed task
err = na1.DeallocateTask(task1)
assert.NoError(t, err)
assert.Check(t, err)
}
func TestAllocateService(t *testing.T) {
@ -549,30 +550,30 @@ func TestAllocateService(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.NotEqual(t, n.IPAM.Configs, nil)
assert.Equal(t, len(n.IPAM.Configs), 1)
assert.Equal(t, n.IPAM.Configs[0].Range, "")
assert.Equal(t, len(n.IPAM.Configs[0].Reserved), 0)
assert.Check(t, err)
assert.Check(t, n.IPAM.Configs != nil)
assert.Check(t, is.Equal(len(n.IPAM.Configs), 1))
assert.Check(t, is.Equal(n.IPAM.Configs[0].Range, ""))
assert.Check(t, is.Equal(len(n.IPAM.Configs[0].Reserved), 0))
_, subnet, err := net.ParseCIDR(n.IPAM.Configs[0].Subnet)
assert.NoError(t, err)
assert.Check(t, err)
gwip := net.ParseIP(n.IPAM.Configs[0].Gateway)
assert.NotEqual(t, gwip, nil)
assert.Check(t, gwip != nil)
err = na.AllocateService(s)
assert.NoError(t, err)
assert.Len(t, s.Endpoint.Ports, 0) // Network allocator is not responsible for allocating ports.
assert.Check(t, err)
assert.Check(t, is.Len(s.Endpoint.Ports, 0)) // Network allocator is not responsible for allocating ports.
assert.Equal(t, 1, len(s.Endpoint.VirtualIPs))
assert.Check(t, is.Equal(1, len(s.Endpoint.VirtualIPs)))
assert.Equal(t, s.Endpoint.Spec, s.Spec.Endpoint)
assert.Check(t, is.DeepEqual(s.Endpoint.Spec, s.Spec.Endpoint))
ip, _, err := net.ParseCIDR(s.Endpoint.VirtualIPs[0].Addr)
assert.NoError(t, err)
assert.Check(t, err)
assert.Equal(t, true, subnet.Contains(ip))
assert.Check(t, is.Equal(true, subnet.Contains(ip)))
}
func TestDeallocateServiceAllocateIngressMode(t *testing.T) {
@ -589,7 +590,7 @@ func TestDeallocateServiceAllocateIngressMode(t *testing.T) {
}
err := na.Allocate(n)
assert.NoError(t, err)
assert.Check(t, err)
s := &api.Service{
ID: "testID1",
@ -612,20 +613,20 @@ func TestDeallocateServiceAllocateIngressMode(t *testing.T) {
&api.Endpoint_VirtualIP{NetworkID: n.ID})
err = na.AllocateService(s)
assert.NoError(t, err)
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Check(t, err)
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 1))
err = na.DeallocateService(s)
assert.NoError(t, err)
assert.Len(t, s.Endpoint.Ports, 0)
assert.Len(t, s.Endpoint.VirtualIPs, 0)
assert.Check(t, err)
assert.Check(t, is.Len(s.Endpoint.Ports, 0))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 0))
// Allocate again.
s.Endpoint.VirtualIPs = append(s.Endpoint.VirtualIPs,
&api.Endpoint_VirtualIP{NetworkID: n.ID})
err = na.AllocateService(s)
assert.NoError(t, err)
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Check(t, err)
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 1))
}
func TestServiceNetworkUpdate(t *testing.T) {
@ -651,10 +652,10 @@ func TestServiceNetworkUpdate(t *testing.T) {
// Allocate both networks
err := na.Allocate(n1)
assert.NoError(t, err)
assert.Check(t, err)
err = na.Allocate(n2)
assert.NoError(t, err)
assert.Check(t, err)
// Attach a network to a service spec nd allocate a service
s := &api.Service{
@ -674,48 +675,48 @@ func TestServiceNetworkUpdate(t *testing.T) {
}
err = na.AllocateService(s)
assert.NoError(t, err)
assert.True(t, na.IsServiceAllocated(s))
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Check(t, err)
assert.Check(t, na.IsServiceAllocated(s))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 1))
// Now update the same service with another network
s.Spec.Task.Networks = append(s.Spec.Task.Networks, &api.NetworkAttachmentConfig{Target: "testID2"})
assert.False(t, na.IsServiceAllocated(s))
assert.Check(t, !na.IsServiceAllocated(s))
err = na.AllocateService(s)
assert.NoError(t, err)
assert.Check(t, err)
assert.True(t, na.IsServiceAllocated(s))
assert.Len(t, s.Endpoint.VirtualIPs, 2)
assert.Check(t, na.IsServiceAllocated(s))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 2))
s.Spec.Task.Networks = s.Spec.Task.Networks[:1]
// Check if service needs update and allocate with updated service spec
assert.False(t, na.IsServiceAllocated(s))
assert.Check(t, !na.IsServiceAllocated(s))
err = na.AllocateService(s)
assert.NoError(t, err)
assert.True(t, na.IsServiceAllocated(s))
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Check(t, err)
assert.Check(t, na.IsServiceAllocated(s))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 1))
s.Spec.Task.Networks = s.Spec.Task.Networks[:0]
// Check if service needs update with all the networks removed and allocate with updated service spec
assert.False(t, na.IsServiceAllocated(s))
assert.Check(t, !na.IsServiceAllocated(s))
err = na.AllocateService(s)
assert.NoError(t, err)
assert.True(t, na.IsServiceAllocated(s))
assert.Len(t, s.Endpoint.VirtualIPs, 0)
assert.Check(t, err)
assert.Check(t, na.IsServiceAllocated(s))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 0))
// Attach a network and allocate service
s.Spec.Task.Networks = append(s.Spec.Task.Networks, &api.NetworkAttachmentConfig{Target: "testID2"})
assert.False(t, na.IsServiceAllocated(s))
assert.Check(t, !na.IsServiceAllocated(s))
err = na.AllocateService(s)
assert.NoError(t, err)
assert.Check(t, err)
assert.True(t, na.IsServiceAllocated(s))
assert.Len(t, s.Endpoint.VirtualIPs, 1)
assert.Check(t, na.IsServiceAllocated(s))
assert.Check(t, is.Len(s.Endpoint.VirtualIPs, 1))
}
@ -758,7 +759,7 @@ func TestCorrectlyPassIPAMOptions(t *testing.T) {
ipamDriver := &mockIpam{}
err = na.(*cnmNetworkAllocator).ipamRegistry.RegisterIpamDriver("mockipam", ipamDriver)
assert.NoError(t, err)
assert.Check(t, err)
n := &api.Network{
ID: "testID",
@ -783,6 +784,6 @@ func TestCorrectlyPassIPAMOptions(t *testing.T) {
}
err = na.Allocate(n)
assert.Equal(t, expectedIpamOptions, ipamDriver.actualIpamOptions)
assert.NoError(t, err)
assert.Check(t, is.DeepEqual(expectedIpamOptions, ipamDriver.actualIpamOptions))
assert.Check(t, err)
}

View file

@ -5,8 +5,9 @@ import (
"github.com/moby/swarmkit/v2/api"
"github.com/moby/swarmkit/v2/testutils"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestValidateDriver(t *testing.T) {
@ -20,11 +21,11 @@ func TestValidateDriver(t *testing.T) {
{"Network", p.ValidateNetworkDriver},
} {
t.Run(tt.name, func(t *testing.T) {
assert.NoError(t, tt.validator(nil))
assert.Check(t, tt.validator(nil))
err := tt.validator(&api.Driver{Name: ""})
assert.Error(t, err)
assert.Equal(t, codes.InvalidArgument, testutils.ErrorCode(err))
assert.Check(t, is.ErrorContains(err, ""))
assert.Check(t, is.Equal(codes.InvalidArgument, testutils.ErrorCode(err)))
})
}
}

View file

@ -87,7 +87,6 @@ require (
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tonistiigi/fsutil v0.0.0-20240223190444-7a889f53dbf6
github.com/tonistiigi/go-archvariant v1.0.0
github.com/vbatts/tar-split v0.11.5
@ -190,6 +189,7 @@ require (
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/spdx/tools-golang v0.5.3 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/tinylib/msgp v1.1.8 // indirect
github.com/tonistiigi/go-actions-cache v0.0.0-20240227172821-a0b64f338598 // indirect