(t *testing.T)
| 27 | ) |
| 28 | |
| 29 | func TestRunContainerWithBridgeNone(t *testing.T) { |
| 30 | skip.If(t, testEnv.IsRemoteDaemon, "cannot start daemon on remote test run") |
| 31 | skip.If(t, testEnv.IsUserNamespace) |
| 32 | |
| 33 | ctx := testutil.StartSpan(baseContext, t) |
| 34 | |
| 35 | d := daemon.New(t) |
| 36 | d.StartWithBusybox(ctx, t, "-b", "none") |
| 37 | defer d.Stop(t) |
| 38 | |
| 39 | c := d.NewClientT(t) |
| 40 | |
| 41 | id1 := container.Run(ctx, t, c) |
| 42 | defer c.ContainerRemove(ctx, id1, client.ContainerRemoveOptions{Force: true}) |
| 43 | |
| 44 | result, err := container.Exec(ctx, c, id1, []string{"ip", "l"}) |
| 45 | assert.NilError(t, err) |
| 46 | assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled") |
| 47 | |
| 48 | id2 := container.Run(ctx, t, c, container.WithNetworkMode("bridge")) |
| 49 | defer c.ContainerRemove(ctx, id2, client.ContainerRemoveOptions{Force: true}) |
| 50 | |
| 51 | result, err = container.Exec(ctx, c, id2, []string{"ip", "l"}) |
| 52 | assert.NilError(t, err) |
| 53 | assert.Check(t, is.Equal(false, strings.Contains(result.Combined(), "eth0")), "There shouldn't be eth0 in container in bridge mode when bridge network is disabled") |
| 54 | |
| 55 | nsCommand := "ls -l /proc/self/ns/net | awk -F '->' '{print $2}'" |
| 56 | cmd := exec.Command("sh", "-c", nsCommand) |
| 57 | stdout := bytes.NewBuffer(nil) |
| 58 | cmd.Stdout = stdout |
| 59 | err = cmd.Run() |
| 60 | assert.NilError(t, err, "Failed to get current process network namespace: %+v", err) |
| 61 | |
| 62 | id3 := container.Run(ctx, t, c, container.WithNetworkMode("host")) |
| 63 | defer c.ContainerRemove(ctx, id3, client.ContainerRemoveOptions{Force: true}) |
| 64 | |
| 65 | result, err = container.Exec(ctx, c, id3, []string{"sh", "-c", nsCommand}) |
| 66 | assert.NilError(t, err) |
| 67 | assert.Check(t, is.Equal(stdout.String(), result.Combined()), "The network namespace of container should be the same with host when --net=host and bridge network is disabled") |
| 68 | } |
| 69 | |
| 70 | func TestHostIPv4BridgeLabel(t *testing.T) { |
| 71 | skip.If(t, testEnv.IsRemoteDaemon) |
nothing calls this directly
no test coverage detected
searching dependent graphs…