Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nhatthm committed Feb 2, 2022
1 parent bca538c commit 25488a2
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"testing"
"time"

"github.com/docker/docker/api/types/container"
"github.com/docker/go-units"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/v3/env"
Expand Down Expand Up @@ -129,10 +131,10 @@ func TestContainerWithHostNetworkOptions(t *testing.T) {

defer nginxC.Terminate(ctx)

//host, err := nginxC.Host(ctx)
//if err != nil {
// host, err := nginxC.Host(ctx)
// if err != nil {
// t.Errorf("Expected host %s. Got '%d'.", host, err)
//}
// }
//
endpoint, err := nginxC.Endpoint(ctx, "http")
if err != nil {
Expand Down Expand Up @@ -1699,6 +1701,49 @@ func TestDockerContainerCopyEmptyFileFromContainer(t *testing.T) {
assert.Empty(t, fileContentFromContainer)
}

func TestDockerContainerResources(t *testing.T) {
ctx := context.Background()

expected := []*units.Ulimit{
{
Name: "memlock",
Hard: -1,
Soft: -1,
},
{
Name: "nofile",
Hard: 65536,
Soft: 65536,
},
}

nginxC, err := GenericContainer(ctx, GenericContainerRequest{
ContainerRequest: ContainerRequest{
Image: "nginx",
ExposedPorts: []string{"80/tcp"},
WaitingFor: wait.ForListeningPort("80/tcp"),
Resources: container.Resources{
Ulimits: expected,
},
},
Started: true,
})
require.NoError(t, err)

defer nginxC.Terminate(ctx)

c, err := client.NewClientWithOpts(client.FromEnv)
require.NoError(t, err)

c.NegotiateAPIVersion(ctx)
containerID := nginxC.GetContainerID()

resp, err := c.ContainerInspect(ctx, containerID)
require.NoError(t, err)

assert.Equal(t, expected, resp.HostConfig.Ulimits)
}

func TestContainerWithReaperNetwork(t *testing.T) {
ctx := context.Background()
networks := []string{
Expand Down

0 comments on commit 25488a2

Please sign in to comment.