summaryrefslogtreecommitdiff
path: root/xdelta3/go/src/xdelta/test.go
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/go/src/xdelta/test.go')
-rw-r--r--xdelta3/go/src/xdelta/test.go21
1 files changed, 7 insertions, 14 deletions
diff --git a/xdelta3/go/src/xdelta/test.go b/xdelta3/go/src/xdelta/test.go
index 427e4c7..00f3dd7 100644
--- a/xdelta3/go/src/xdelta/test.go
+++ b/xdelta3/go/src/xdelta/test.go
@@ -35,9 +35,8 @@ type Run struct {
35 35
36func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte { 36func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte {
37 c := make(chan []byte) 37 c := make(chan []byte)
38 t.Go(desc, func(g Goroutine) { 38 t.Go(desc, func(g *Goroutine) {
39 if b, err := ioutil.ReadAll(f); err != nil { 39 if b, err := ioutil.ReadAll(f); err != nil {
40 fmt.Println("Drain", err)
41 g.Panic(err) 40 g.Panic(err)
42 } else { 41 } else {
43 c <- b 42 c <- b
@@ -47,8 +46,8 @@ func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte {
47 return c 46 return c
48} 47}
49 48
50func (t *TestGroup) Empty(f io.ReadCloser, desc string) Goroutine { 49func (t *TestGroup) Empty(f io.ReadCloser, desc string) *Goroutine {
51 return t.Go("empty:"+desc, func (g Goroutine) { 50 return t.Go("empty:"+desc, func (g *Goroutine) {
52 s := bufio.NewScanner(f) 51 s := bufio.NewScanner(f)
53 for s.Scan() { 52 for s.Scan() {
54 os.Stderr.Write([]byte(fmt.Sprint(desc, ": ", s.Text(), "\n"))) 53 os.Stderr.Write([]byte(fmt.Sprint(desc, ": ", s.Text(), "\n")))
@@ -64,18 +63,16 @@ func (t *TestGroup) Empty(f io.ReadCloser, desc string) Goroutine {
64 63
65func TestWrite(what string, f io.WriteCloser, b []byte) error { 64func TestWrite(what string, f io.WriteCloser, b []byte) error {
66 if _, err := f.Write(b); err != nil { 65 if _, err := f.Write(b); err != nil {
67 fmt.Println("Write", err)
68 return errors.New(fmt.Sprint(what, ":", err)) 66 return errors.New(fmt.Sprint(what, ":", err))
69 } 67 }
70 if err := f.Close(); err != nil { 68 if err := f.Close(); err != nil {
71 fmt.Println("Close", err)
72 return errors.New(fmt.Sprint(what, ":", err)) 69 return errors.New(fmt.Sprint(what, ":", err))
73 } 70 }
74 return nil 71 return nil
75} 72}
76 73
77func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) Goroutine { 74func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) *Goroutine {
78 return t.Go("copy", func(g Goroutine) { 75 return t.Go("copy", func(g *Goroutine) {
79 _, err := io.Copy(w, r) 76 _, err := io.Copy(w, r)
80 if err != nil { 77 if err != nil {
81 g.Panic(err) 78 g.Panic(err)
@@ -92,8 +89,8 @@ func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) Goroutine {
92 }) 89 })
93} 90}
94 91
95func (t *TestGroup) CompareStreams(r1 io.ReadCloser, r2 io.ReadCloser, length int64) Goroutine { 92func (t *TestGroup) CompareStreams(r1 io.ReadCloser, r2 io.ReadCloser, length int64) *Goroutine {
96 return t.Go("compare", func(g Goroutine) { 93 return t.Go("compare", func(g *Goroutine) {
97 b1 := make([]byte, blocksize) 94 b1 := make([]byte, blocksize)
98 b2 := make([]byte, blocksize) 95 b2 := make([]byte, blocksize)
99 var idx int64 96 var idx int64
@@ -103,11 +100,9 @@ func (t *TestGroup) CompareStreams(r1 io.ReadCloser, r2 io.ReadCloser, length in
103 c = int(length) 100 c = int(length)
104 } 101 }
105 if _, err := io.ReadFull(r1, b1[0:c]); err != nil { 102 if _, err := io.ReadFull(r1, b1[0:c]); err != nil {
106 fmt.Println("ReadFull1", err)
107 g.Panic(err) 103 g.Panic(err)
108 } 104 }
109 if _, err := io.ReadFull(r2, b2[0:c]); err != nil { 105 if _, err := io.ReadFull(r2, b2[0:c]); err != nil {
110 fmt.Println("ReadFull2", err)
111 g.Panic(err) 106 g.Panic(err)
112 } 107 }
113 if bytes.Compare(b1[0:c], b2[0:c]) != 0 { 108 if bytes.Compare(b1[0:c], b2[0:c]) != 0 {
@@ -166,9 +161,7 @@ func (r *Run) Wait() error {
166} 161}
167 162
168func writeFifo(srcfile string, read io.Reader) error { 163func writeFifo(srcfile string, read io.Reader) error {
169 fmt.Println("About to open", srcfile)
170 fifo, err := os.OpenFile(srcfile, os.O_WRONLY, 0600) 164 fifo, err := os.OpenFile(srcfile, os.O_WRONLY, 0600)
171 fmt.Println("Opened!!!", srcfile)
172 if err != nil { 165 if err != nil {
173 fifo.Close() 166 fifo.Close()
174 return err 167 return err