stats_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package container // import "github.com/docker/docker/integration/container"
  2. import (
  3. "context"
  4. "encoding/json"
  5. "io"
  6. "testing"
  7. "time"
  8. "github.com/docker/docker/api/types"
  9. "github.com/docker/docker/integration/internal/container"
  10. "github.com/docker/docker/integration/internal/request"
  11. "github.com/gotestyourself/gotestyourself/poll"
  12. "github.com/gotestyourself/gotestyourself/skip"
  13. "github.com/stretchr/testify/assert"
  14. "github.com/stretchr/testify/require"
  15. )
  16. func TestStats(t *testing.T) {
  17. skip.If(t, !testEnv.DaemonInfo.MemoryLimit)
  18. defer setupTest(t)()
  19. client := request.NewAPIClient(t)
  20. ctx := context.Background()
  21. info, err := client.Info(ctx)
  22. require.NoError(t, err)
  23. cID := container.Run(t, ctx, client)
  24. poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond))
  25. resp, err := client.ContainerStats(ctx, cID, false)
  26. require.NoError(t, err)
  27. defer resp.Body.Close()
  28. var v *types.Stats
  29. err = json.NewDecoder(resp.Body).Decode(&v)
  30. require.NoError(t, err)
  31. assert.Equal(t, int64(v.MemoryStats.Limit), info.MemTotal)
  32. err = json.NewDecoder(resp.Body).Decode(&v)
  33. require.Error(t, err, io.EOF)
  34. }