github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/integration/network/bridge_test.go (about) 1 package network 2 3 import ( 4 "context" 5 "strings" 6 "testing" 7 "time" 8 9 networktypes "github.com/Prakhar-Agarwal-byte/moby/api/types/network" 10 "github.com/Prakhar-Agarwal-byte/moby/api/types/versions" 11 ctr "github.com/Prakhar-Agarwal-byte/moby/integration/internal/container" 12 "github.com/Prakhar-Agarwal-byte/moby/integration/internal/network" 13 "gotest.tools/v3/assert" 14 "gotest.tools/v3/skip" 15 ) 16 17 func TestCreateWithMultiNetworks(t *testing.T) { 18 skip.If(t, testEnv.DaemonInfo.OSType == "windows") 19 skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.44"), "requires API v1.44") 20 21 ctx := setupTest(t) 22 apiClient := testEnv.APIClient() 23 24 network.CreateNoError(ctx, t, apiClient, "testnet1") 25 defer network.RemoveNoError(ctx, t, apiClient, "testnet1") 26 27 network.CreateNoError(ctx, t, apiClient, "testnet2") 28 defer network.RemoveNoError(ctx, t, apiClient, "testnet2") 29 30 attachCtx, cancel := context.WithTimeout(ctx, 1*time.Second) 31 defer cancel() 32 res := ctr.RunAttach(attachCtx, t, apiClient, 33 ctr.WithCmd("ip", "-o", "-4", "addr", "show"), 34 ctr.WithNetworkMode("testnet1"), 35 ctr.WithEndpointSettings("testnet1", &networktypes.EndpointSettings{}), 36 ctr.WithEndpointSettings("testnet2", &networktypes.EndpointSettings{})) 37 38 assert.Equal(t, res.ExitCode, 0) 39 assert.Equal(t, res.Stderr.String(), "") 40 41 // Only interfaces with an IPv4 address are printed by iproute2 when flag -4 is specified. Here, we should have two 42 // interfaces for testnet1 and testnet2, plus lo. 43 ifacesWithAddress := strings.Count(res.Stdout.String(), "\n") 44 assert.Equal(t, ifacesWithAddress, 3) 45 }