github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration/container/run_linux_test.go (about)

     1  package container // import "github.com/docker/docker/integration/container"
     2  
     3  import (
     4  	"context"
     5  	"strconv"
     6  	"strings"
     7  	"testing"
     8  	"time"
     9  
    10  	containertypes "github.com/docker/docker/api/types/container"
    11  	"github.com/docker/docker/api/types/versions"
    12  	"github.com/docker/docker/integration/internal/container"
    13  	"gotest.tools/assert"
    14  	is "gotest.tools/assert/cmp"
    15  	"gotest.tools/poll"
    16  	"gotest.tools/skip"
    17  )
    18  
    19  func TestKernelTCPMemory(t *testing.T) {
    20  	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
    21  	skip.If(t, versions.LessThan(testEnv.DaemonAPIVersion(), "1.40"), "skip test from new feature")
    22  	skip.If(t, !testEnv.DaemonInfo.KernelMemoryTCP)
    23  
    24  	defer setupTest(t)()
    25  	client := testEnv.APIClient()
    26  	ctx := context.Background()
    27  
    28  	const (
    29  		kernelMemoryTCP int64 = 200 * 1024 * 1024
    30  	)
    31  
    32  	cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) {
    33  		c.HostConfig.Resources = containertypes.Resources{
    34  			KernelMemoryTCP: kernelMemoryTCP,
    35  		}
    36  	})
    37  
    38  	poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
    39  
    40  	inspect, err := client.ContainerInspect(ctx, cID)
    41  	assert.NilError(t, err)
    42  	assert.Check(t, is.Equal(kernelMemoryTCP, inspect.HostConfig.KernelMemoryTCP))
    43  
    44  	res, err := container.Exec(ctx, client, cID,
    45  		[]string{"cat", "/sys/fs/cgroup/memory/memory.kmem.tcp.limit_in_bytes"})
    46  	assert.NilError(t, err)
    47  	assert.Assert(t, is.Len(res.Stderr(), 0))
    48  	assert.Equal(t, 0, res.ExitCode)
    49  	assert.Check(t, is.Equal(strconv.FormatInt(kernelMemoryTCP, 10), strings.TrimSpace(res.Stdout())))
    50  }
    51  
    52  func TestNISDomainname(t *testing.T) {
    53  	skip.If(t, testEnv.DaemonInfo.OSType != "linux")
    54  
    55  	defer setupTest(t)()
    56  	client := testEnv.APIClient()
    57  	ctx := context.Background()
    58  
    59  	const (
    60  		hostname   = "foobar"
    61  		domainname = "baz.cyphar.com"
    62  	)
    63  
    64  	cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) {
    65  		c.Config.Hostname = hostname
    66  		c.Config.Domainname = domainname
    67  	})
    68  
    69  	poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
    70  
    71  	inspect, err := client.ContainerInspect(ctx, cID)
    72  	assert.NilError(t, err)
    73  	assert.Check(t, is.Equal(hostname, inspect.Config.Hostname))
    74  	assert.Check(t, is.Equal(domainname, inspect.Config.Domainname))
    75  
    76  	// Check hostname.
    77  	res, err := container.Exec(ctx, client, cID,
    78  		[]string{"cat", "/proc/sys/kernel/hostname"})
    79  	assert.NilError(t, err)
    80  	assert.Assert(t, is.Len(res.Stderr(), 0))
    81  	assert.Equal(t, 0, res.ExitCode)
    82  	assert.Check(t, is.Equal(hostname, strings.TrimSpace(res.Stdout())))
    83  
    84  	// Check domainname.
    85  	res, err = container.Exec(ctx, client, cID,
    86  		[]string{"cat", "/proc/sys/kernel/domainname"})
    87  	assert.NilError(t, err)
    88  	assert.Assert(t, is.Len(res.Stderr(), 0))
    89  	assert.Equal(t, 0, res.ExitCode)
    90  	assert.Check(t, is.Equal(domainname, strings.TrimSpace(res.Stdout())))
    91  }