2023-08-10 10:50:13 +00:00
|
|
|
//go:build !windows
|
|
|
|
|
2017-10-19 11:36:29 +00:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
2023-07-26 19:06:35 +00:00
|
|
|
"github.com/docker/docker/internal/testutils/netnsutils"
|
2020-08-31 15:55:22 +00:00
|
|
|
"gotest.tools/v3/assert"
|
2017-10-19 11:36:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestCleanupServiceDiscovery(t *testing.T) {
|
2023-07-26 19:06:35 +00:00
|
|
|
defer netnsutils.SetupTestOSContext(t)()
|
2024-01-31 22:24:47 +00:00
|
|
|
c, err := New(OptionBoltdbWithRandomDBFile(t))
|
2018-07-04 09:01:52 +00:00
|
|
|
assert.NilError(t, err)
|
2017-10-19 11:36:29 +00:00
|
|
|
defer c.Stop()
|
|
|
|
|
2023-07-21 22:38:57 +00:00
|
|
|
cleanup := func(n *Network) {
|
2021-05-28 00:15:56 +00:00
|
|
|
if err := n.Delete(); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
2017-10-19 11:36:29 +00:00
|
|
|
n1, err := c.NewNetwork("bridge", "net1", "", nil)
|
2018-07-04 09:01:52 +00:00
|
|
|
assert.NilError(t, err)
|
2021-05-28 00:15:56 +00:00
|
|
|
defer cleanup(n1)
|
2017-10-19 11:36:29 +00:00
|
|
|
|
|
|
|
n2, err := c.NewNetwork("bridge", "net2", "", nil)
|
2018-07-04 09:01:52 +00:00
|
|
|
assert.NilError(t, err)
|
2021-05-28 00:15:56 +00:00
|
|
|
defer cleanup(n2)
|
2017-10-19 11:36:29 +00:00
|
|
|
|
2023-07-21 22:38:57 +00:00
|
|
|
n1.addSvcRecords("N1ep1", "service_test", "serviceID1", net.ParseIP("192.168.0.1"), net.IP{}, true, "test")
|
|
|
|
n1.addSvcRecords("N2ep2", "service_test", "serviceID2", net.ParseIP("192.168.0.2"), net.IP{}, true, "test")
|
2017-10-19 11:36:29 +00:00
|
|
|
|
2023-07-21 22:38:57 +00:00
|
|
|
n2.addSvcRecords("N2ep1", "service_test", "serviceID1", net.ParseIP("192.168.1.1"), net.IP{}, true, "test")
|
|
|
|
n2.addSvcRecords("N2ep2", "service_test", "serviceID2", net.ParseIP("192.168.1.2"), net.IP{}, true, "test")
|
2017-10-19 11:36:29 +00:00
|
|
|
|
2023-01-11 22:43:32 +00:00
|
|
|
if len(c.svcRecords) != 2 {
|
|
|
|
t.Fatalf("Service record not added correctly:%v", c.svcRecords)
|
2017-10-19 11:36:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup net1
|
2023-01-11 22:43:32 +00:00
|
|
|
c.cleanupServiceDiscovery(n1.ID())
|
2017-10-19 11:36:29 +00:00
|
|
|
|
2023-01-11 22:43:32 +00:00
|
|
|
if len(c.svcRecords) != 1 {
|
|
|
|
t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
|
2017-10-19 11:36:29 +00:00
|
|
|
}
|
|
|
|
|
2023-01-11 22:43:32 +00:00
|
|
|
c.cleanupServiceDiscovery("")
|
2017-10-19 11:36:29 +00:00
|
|
|
|
2023-01-11 22:43:32 +00:00
|
|
|
if len(c.svcRecords) != 0 {
|
|
|
|
t.Fatalf("Service record not cleaned correctly:%v", c.svcRecords)
|
2017-10-19 11:36:29 +00:00
|
|
|
}
|
|
|
|
}
|