2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-02-01 11:35:13 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-02-12 18:08:25 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-02-09 13:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/request"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
|
|
|
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
2018-02-01 11:35:13 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/poll"
|
|
|
|
"github.com/gotestyourself/gotestyourself/skip"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestStats(t *testing.T) {
|
|
|
|
skip.If(t, !testEnv.DaemonInfo.MemoryLimit)
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
client := request.NewAPIClient(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
info, err := client.Info(ctx)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-01 11:35:13 -05:00
|
|
|
|
2018-02-12 18:08:25 -05:00
|
|
|
cID := container.Run(t, ctx, client)
|
2018-02-01 11:35:13 -05:00
|
|
|
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
|
2018-02-01 11:35:13 -05:00
|
|
|
|
2018-02-12 18:08:25 -05:00
|
|
|
resp, err := client.ContainerStats(ctx, cID, false)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-02-01 11:35:13 -05:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
|
|
|
var v *types.Stats
|
|
|
|
err = json.NewDecoder(resp.Body).Decode(&v)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.Equal(int64(v.MemoryStats.Limit), info.MemTotal))
|
2018-02-01 11:35:13 -05:00
|
|
|
err = json.NewDecoder(resp.Body).Decode(&v)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Assert(t, is.ErrorContains(err, ""), io.EOF)
|
2018-02-01 11:35:13 -05:00
|
|
|
}
|