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.go55
1 files changed, 22 insertions, 33 deletions
diff --git a/xdelta3/go/src/xdelta/test.go b/xdelta3/go/src/xdelta/test.go
index 00f3dd7..bab66f3 100644
--- a/xdelta3/go/src/xdelta/test.go
+++ b/xdelta3/go/src/xdelta/test.go
@@ -8,7 +8,6 @@ import (
8 "io" 8 "io"
9 "io/ioutil" 9 "io/ioutil"
10 "os" 10 "os"
11 "os/exec"
12 "path" 11 "path"
13 "sync/atomic" 12 "sync/atomic"
14 13
@@ -20,19 +19,6 @@ var (
20 srcSeq int64 19 srcSeq int64
21) 20)
22 21
23type Program struct {
24 Path string
25}
26
27type Run struct {
28 Cmd exec.Cmd
29 Srcfile string
30 Stdin io.WriteCloser
31 Srcin io.WriteCloser
32 Stdout io.ReadCloser
33 Stderr io.ReadCloser
34}
35
36func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte { 22func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte {
37 c := make(chan []byte) 23 c := make(chan []byte)
38 t.Go(desc, func(g *Goroutine) { 24 t.Go(desc, func(g *Goroutine) {
@@ -71,9 +57,9 @@ func TestWrite(what string, f io.WriteCloser, b []byte) error {
71 return nil 57 return nil
72} 58}
73 59
74func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) *Goroutine { 60func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser, written *int64) *Goroutine {
75 return t.Go("copy", func(g *Goroutine) { 61 return t.Go("copy", func(g *Goroutine) {
76 _, err := io.Copy(w, r) 62 nwrite, err := io.Copy(w, r)
77 if err != nil { 63 if err != nil {
78 g.Panic(err) 64 g.Panic(err)
79 } 65 }
@@ -86,6 +72,7 @@ func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) *Goroutine {
86 g.Panic(err) 72 g.Panic(err)
87 } 73 }
88 g.OK() 74 g.OK()
75 *written = nwrite
89 }) 76 })
90} 77}
91 78
@@ -127,12 +114,9 @@ func (t *TestGroup) Exec(desc string, p *Program, srcfifo bool, flags []string)
127 if err = unix.Mkfifo(run.Srcfile, 0600); err != nil { 114 if err = unix.Mkfifo(run.Srcfile, 0600); err != nil {
128 return nil, err 115 return nil, err
129 } 116 }
130 // Because OpenFile blocks on the Fifo until the reader
131 // arrives, a pipe to defer open
132 read, write := io.Pipe() 117 read, write := io.Pipe()
118 t.writeFifo(run.Srcfile, read)
133 run.Srcin = write 119 run.Srcin = write
134
135 go writeFifo(run.Srcfile, read)
136 args = append(args, "-s") 120 args = append(args, "-s")
137 args = append(args, run.Srcfile) 121 args = append(args, run.Srcfile)
138 } 122 }
@@ -156,19 +140,24 @@ func (t *TestGroup) Exec(desc string, p *Program, srcfifo bool, flags []string)
156 return run, nil 140 return run, nil
157} 141}
158 142
159func (r *Run) Wait() error { 143func (t *TestGroup) Fail(v ...interface{}) {
160 return r.Cmd.Wait() 144 panic(fmt.Sprintln(v...))
161} 145}
162 146
163func writeFifo(srcfile string, read io.Reader) error { 147func (t *TestGroup) writeFifo(srcfile string, read io.Reader) *Goroutine {
164 fifo, err := os.OpenFile(srcfile, os.O_WRONLY, 0600) 148 return t.Go("compare", func(g *Goroutine) {
165 if err != nil { 149 fifo, err := os.OpenFile(srcfile, os.O_WRONLY, 0600)
166 fifo.Close() 150 if err != nil {
167 return err 151 fifo.Close()
168 } 152 g.Panic(err)
169 if _, err := io.Copy(fifo, read); err != nil { 153 }
170 fifo.Close() 154 if _, err := io.Copy(fifo, read); err != nil {
171 return err 155 fifo.Close()
172 } 156 g.Panic(err)
173 return fifo.Close() 157 }
158 if err := fifo.Close(); err != nil {
159 g.Panic(err)
160 }
161 g.OK()
162 })
174} 163}