1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add "nuke" function to docker tests to avoid disk space waste

This commit is contained in:
Guillaume J. Charmes 2013-03-12 00:08:41 -07:00
parent 132ecb2482
commit e0b09d4933
7 changed files with 28 additions and 5 deletions

View file

@ -3,7 +3,7 @@ package docker
import (
"encoding/json"
"errors"
"github.com/dotcloud/docker/fs"
"./fs"
"github.com/kr/pty"
"io"
"io/ioutil"

View file

@ -15,6 +15,7 @@ func TestStart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"start_test",
"ls",
@ -51,6 +52,7 @@ func TestRun(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"run_test",
"ls",
@ -81,6 +83,7 @@ func TestOutput(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"output_test",
"echo",
@ -106,6 +109,7 @@ func TestKill(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"stop_test",
"cat",
@ -148,6 +152,7 @@ func TestExitCode(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
trueContainer, err := docker.Create(
"exit_test_1",
@ -193,6 +198,7 @@ func TestRestart(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"restart_test",
"echo",
@ -227,6 +233,7 @@ func TestRestartStdin(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"restart_stdin_test",
"cat",
@ -276,6 +283,7 @@ func TestUser(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
// Default user must be root
container, err := docker.Create(
@ -393,6 +401,7 @@ func TestMultipleContainers(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container1, err := docker.Create(
"container1",
@ -449,6 +458,7 @@ func TestStdin(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"stdin_test",
"cat",
@ -484,6 +494,7 @@ func TestTty(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"tty_test",
"cat",
@ -519,6 +530,7 @@ func TestEnv(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"env_test",
"/usr/bin/env",
@ -568,6 +580,7 @@ func BenchmarkRunSequencial(b *testing.B) {
if err != nil {
b.Fatal(err)
}
defer nuke(docker)
for i := 0; i < b.N; i++ {
container, err := docker.Create(
fmt.Sprintf("bench_%v", i),
@ -598,6 +611,7 @@ func BenchmarkRunParallel(b *testing.B) {
if err != nil {
b.Fatal(err)
}
defer nuke(docker)
var tasks []chan error

View file

@ -1,7 +1,7 @@
package docker
import (
"github.com/dotcloud/docker/fs"
"./fs"
"container/list"
"fmt"
"io/ioutil"

View file

@ -11,6 +11,10 @@ import (
const testLayerPath string = "/var/lib/docker/docker-ut.tar"
func nuke(docker *Docker) error {
return os.RemoveAll(docker.root)
}
func layerArchive(tarfile string) (io.Reader, error) {
// FIXME: need to close f somewhere
f, err := os.Open(tarfile)
@ -72,6 +76,7 @@ func TestCreate(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
// Make sure we start we 0 containers
if len(docker.List()) != 0 {
@ -125,6 +130,7 @@ func TestDestroy(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container, err := docker.Create(
"test_destroy",
"ls",
@ -173,6 +179,7 @@ func TestGet(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker)
container1, err := docker.Create(
"test1",
"ls",
@ -233,6 +240,7 @@ func TestRestore(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker1)
if layer, err := layerArchive(testLayerPath); err != nil {
panic(err)
@ -268,6 +276,7 @@ func TestRestore(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer nuke(docker2)
if len(docker2.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker2.List()))
}

View file

@ -1,7 +1,7 @@
package fs
import (
"github.com/dotcloud/docker/future"
"../future"
"errors"
"fmt"
"io"

View file

@ -4,7 +4,7 @@ import (
"database/sql"
"errors"
"fmt"
"github.com/dotcloud/docker/future"
"../future"
_ "github.com/mattn/go-sqlite3"
"github.com/shykes/gorp" //Forked to implement CreateTablesOpts
"io"

View file

@ -2,7 +2,7 @@ package docker
import (
"fmt"
"github.com/dotcloud/docker/future"
"./future"
"sync"
"time"
)