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

Removed 'fake' package.

This commit is contained in:
shin- 2013-03-20 07:49:38 -07:00
parent a3174fd874
commit 6d580247c2
5 changed files with 52 additions and 92 deletions

View file

@ -1,74 +0,0 @@
package fake
import (
"archive/tar"
"bytes"
"github.com/kr/pty"
"io"
"math/rand"
"os/exec"
)
func FakeTar() (io.Reader, error) {
content := []byte("Hello world!\n")
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
for _, name := range []string{"/etc/postgres/postgres.conf", "/etc/passwd", "/var/log/postgres/postgres.conf"} {
hdr := new(tar.Header)
hdr.Size = int64(len(content))
hdr.Name = name
if err := tw.WriteHeader(hdr); err != nil {
return nil, err
}
tw.Write([]byte(content))
}
tw.Close()
return buf, nil
}
func WriteFakeTar(dst io.Writer) error {
if data, err := FakeTar(); err != nil {
return err
} else if _, err := io.Copy(dst, data); err != nil {
return err
}
return nil
}
func RandomBytesChanged() uint {
return uint(rand.Int31n(24 * 1024 * 1024))
}
func RandomFilesChanged() uint {
return uint(rand.Int31n(42))
}
func RandomContainerSize() uint {
return uint(rand.Int31n(142 * 1024 * 1024))
}
func ContainerRunning() bool {
return false
}
func StartCommand(cmd *exec.Cmd, interactive bool) (io.WriteCloser, io.ReadCloser, error) {
if interactive {
term, err := pty.Start(cmd)
if err != nil {
return nil, nil, err
}
return term, term, nil
}
stdin, err := cmd.StdinPipe()
if err != nil {
return nil, nil, err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, nil, err
}
if err := cmd.Start(); err != nil {
return nil, nil, err
}
return stdin, stdout, nil
}

View file

@ -1,12 +1,31 @@
package fs
import (
"github.com/dotcloud/docker/fake"
"archive/tar"
"bytes"
"io"
"io/ioutil"
"os"
"testing"
)
func fakeTar() (io.Reader, error) {
content := []byte("Hello world!\n")
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
for _, name := range []string{"/etc/postgres/postgres.conf", "/etc/passwd", "/var/log/postgres/postgres.conf"} {
hdr := new(tar.Header)
hdr.Size = int64(len(content))
hdr.Name = name
if err := tw.WriteHeader(hdr); err != nil {
return nil, err
}
tw.Write([]byte(content))
}
tw.Close()
return buf, nil
}
func TestLayersInit(t *testing.T) {
store := tempStore(t)
defer os.RemoveAll(store.Root)
@ -69,7 +88,7 @@ func tempStore(t *testing.T) *LayerStore {
}
func testArchive(t *testing.T) Archive {
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}

View file

@ -2,7 +2,6 @@ package fs
import (
"fmt"
"github.com/dotcloud/docker/fake"
"testing"
)
@ -20,7 +19,7 @@ func TestRemoveInPath(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -75,7 +74,7 @@ func TestRemove(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -141,7 +140,7 @@ func TestRemoveRegexp(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}

View file

@ -2,7 +2,6 @@ package fs
import (
"fmt"
"github.com/dotcloud/docker/fake"
"github.com/dotcloud/docker/future"
"io/ioutil"
"os"
@ -10,8 +9,6 @@ import (
"time"
)
// FIXME: Remove the Fake package
func TestInit(t *testing.T) {
store, err := TempStore("testinit")
if err != nil {
@ -35,7 +32,7 @@ func TestCreate(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -63,7 +60,7 @@ func TestRegister(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -97,7 +94,7 @@ func TestTag(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -129,7 +126,7 @@ func TestCopyNewPath(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -169,7 +166,7 @@ func TestCopySameName(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -189,7 +186,7 @@ func TestMountPoint(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}
@ -215,7 +212,7 @@ func TestMountpointDuplicateRoot(t *testing.T) {
t.Fatal(err)
}
defer nuke(store)
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}

View file

@ -1,14 +1,33 @@
package docker
import (
"archive/tar"
"bytes"
"fmt"
"github.com/dotcloud/docker/fake"
"github.com/dotcloud/docker/fs"
"io"
"io/ioutil"
"os"
"testing"
)
func fakeTar() (io.Reader, error) {
content := []byte("Hello world!\n")
buf := new(bytes.Buffer)
tw := tar.NewWriter(buf)
for _, name := range []string{"/etc/postgres/postgres.conf", "/etc/passwd", "/var/log/postgres/postgres.conf"} {
hdr := new(tar.Header)
hdr.Size = int64(len(content))
hdr.Name = name
if err := tw.WriteHeader(hdr); err != nil {
return nil, err
}
tw.Write([]byte(content))
}
tw.Close()
return buf, nil
}
// Look for inconsistencies in a store.
func healthCheck(store *fs.Store) error {
parents := make(map[string]bool)
@ -57,7 +76,7 @@ func TestMount(t *testing.T) {
t.Fatal(err)
}
archive, err := fake.FakeTar()
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
}