commit
c751e1739d
|
@ -686,10 +686,14 @@ func (container *Container) Mount() error {
|
||||||
return container.daemon.Mount(container)
|
return container.daemon.Mount(container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (container *Container) changes() ([]archive.Change, error) {
|
||||||
|
return container.daemon.Changes(container)
|
||||||
|
}
|
||||||
|
|
||||||
func (container *Container) Changes() ([]archive.Change, error) {
|
func (container *Container) Changes() ([]archive.Change, error) {
|
||||||
container.Lock()
|
container.Lock()
|
||||||
defer container.Unlock()
|
defer container.Unlock()
|
||||||
return container.daemon.Changes(container)
|
return container.changes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (container *Container) GetImage() (*image.Image, error) {
|
func (container *Container) GetImage() (*image.Image, error) {
|
||||||
|
@ -750,7 +754,7 @@ func (container *Container) GetSize() (int64, int64) {
|
||||||
}
|
}
|
||||||
defer container.Unmount()
|
defer container.Unmount()
|
||||||
|
|
||||||
if differ, ok := container.daemon.driver.(graphdriver.Differ); ok {
|
if differ, ok := driver.(graphdriver.Differ); ok {
|
||||||
sizeRw, err = differ.DiffSize(container.ID)
|
sizeRw, err = differ.DiffSize(container.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err)
|
log.Errorf("Warning: driver %s couldn't return diff size of container %s: %s", driver, container.ID, err)
|
||||||
|
@ -759,7 +763,7 @@ func (container *Container) GetSize() (int64, int64) {
|
||||||
sizeRw = -1
|
sizeRw = -1
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
changes, _ := container.Changes()
|
changes, _ := container.changes()
|
||||||
if changes != nil {
|
if changes != nil {
|
||||||
sizeRw = archive.ChangesSize(container.basefs, changes)
|
sizeRw = archive.ChangesSize(container.basefs, changes)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestListContainers(t *testing.T) {
|
func TestListContainers(t *testing.T) {
|
||||||
|
@ -199,3 +200,39 @@ func assertContainerList(out string, expected []string) bool {
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestListContainersSize(t *testing.T) {
|
||||||
|
name := "test_size"
|
||||||
|
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "sh", "-c", "echo 1 > test")
|
||||||
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
|
errorOut(err, t, out)
|
||||||
|
id, err := getIDByName(name)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
runCmd = exec.Command(dockerBinary, "ps", "-s", "-n=1")
|
||||||
|
wait := make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
|
close(wait)
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-wait:
|
||||||
|
case <-time.After(3 * time.Second):
|
||||||
|
t.Fatalf("Calling \"docker ps -s\" timed out!")
|
||||||
|
}
|
||||||
|
errorOut(err, t, out)
|
||||||
|
lines := strings.Split(strings.Trim(out, "\n "), "\n")
|
||||||
|
sizeIndex := strings.Index(lines[0], "SIZE")
|
||||||
|
idIndex := strings.Index(lines[0], "CONTAINER ID")
|
||||||
|
foundID := lines[1][idIndex : idIndex+12]
|
||||||
|
if foundID != id[:12] {
|
||||||
|
t.Fatalf("Expected id %s, got %s", id[:12], foundID)
|
||||||
|
}
|
||||||
|
expectedSize := "2 B"
|
||||||
|
foundSize := lines[1][sizeIndex:]
|
||||||
|
if foundSize != expectedSize {
|
||||||
|
t.Fatalf("Expected size %q, got %q", expectedSize, foundSize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue