Use go-units to parse/format.
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
| ... | ... |
@@ -4,7 +4,6 @@ import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"sort" |
| 7 |
- "strconv" |
|
| 8 | 7 |
"strings" |
| 9 | 8 |
"testing" |
| 10 | 9 |
"time" |
| ... | ... |
@@ -13,6 +12,7 @@ import ( |
| 13 | 13 |
"github.com/docker/docker/integration-cli/cli" |
| 14 | 14 |
"github.com/docker/docker/integration-cli/cli/build" |
| 15 | 15 |
"github.com/docker/docker/pkg/stringid" |
| 16 |
+ "github.com/docker/go-units" |
|
| 16 | 17 |
"gotest.tools/v3/assert" |
| 17 | 18 |
is "gotest.tools/v3/assert/cmp" |
| 18 | 19 |
"gotest.tools/v3/icmd" |
| ... | ... |
@@ -159,8 +159,8 @@ func (s *DockerCLIPsSuite) TestPsListContainersSize(c *testing.T) {
|
| 159 | 159 |
baseOut, _ := dockerCmd(c, "ps", "-s", "-n=1") |
| 160 | 160 |
baseLines := strings.Split(strings.Trim(baseOut, "\n "), "\n") |
| 161 | 161 |
baseSizeIndex := strings.Index(baseLines[0], "SIZE") |
| 162 |
- baseFoundsize := baseLines[1][baseSizeIndex:] |
|
| 163 |
- baseBytes, err := strconv.Atoi(strings.Split(baseFoundsize, "B")[0]) |
|
| 162 |
+ baseFoundsize, _, _ := strings.Cut(baseLines[1][baseSizeIndex:], " ") |
|
| 163 |
+ baseBytes, err := units.FromHumanSize(baseFoundsize) |
|
| 164 | 164 |
assert.NilError(c, err) |
| 165 | 165 |
|
| 166 | 166 |
name := "test_size" |
| ... | ... |
@@ -186,7 +186,7 @@ func (s *DockerCLIPsSuite) TestPsListContainersSize(c *testing.T) {
|
| 186 | 186 |
idIndex := strings.Index(lines[0], "CONTAINER ID") |
| 187 | 187 |
foundID := lines[1][idIndex : idIndex+12] |
| 188 | 188 |
assert.Equal(c, foundID, id[:12], fmt.Sprintf("Expected id %s, got %s", id[:12], foundID))
|
| 189 |
- expectedSize := fmt.Sprintf("%dB", 2+baseBytes)
|
|
| 189 |
+ expectedSize := units.HumanSize(float64(baseBytes + 2)) |
|
| 190 | 190 |
foundSize := lines[1][sizeIndex:] |
| 191 | 191 |
assert.Assert(c, strings.Contains(foundSize, expectedSize), "Expected size %q, got %q", expectedSize, foundSize) |
| 192 | 192 |
} |