-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathcopy_test.go
More file actions
60 lines (47 loc) · 1.77 KB
/
Copy pathcopy_test.go
File metadata and controls
60 lines (47 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package boxlite
import (
"context"
"errors"
"io"
"testing"
)
type failingWriter struct{ err error }
func (f failingWriter) Write([]byte) (int, error) { return 0, f.err }
type shortWriter struct{}
func (shortWriter) Write(p []byte) (int, error) { return len(p) - 1, nil }
func TestWriteCopyOutChunkSurfacesWriterError(t *testing.T) {
want := errors.New("client gone")
if err := writeCopyOutChunk(failingWriter{err: want}, []byte("chunk")); !errors.Is(err, want) {
t.Fatalf("writeCopyOutChunk() error = %v, want %v", err, want)
}
}
func TestWriteCopyOutChunkRejectsShortWrite(t *testing.T) {
if err := writeCopyOutChunk(shortWriter{}, []byte("chunk")); !errors.Is(err, io.ErrShortWrite) {
t.Fatalf("writeCopyOutChunk() error = %v, want %v", err, io.ErrShortWrite)
}
}
func TestDeliverCopyOutMetaMapsKnownKinds(t *testing.T) {
var got []bool
onMeta := func(sourceIsDir bool) { got = append(got, sourceIsDir) }
deliverCopyOutMeta(CopySourceUnknown, onMeta)
deliverCopyOutMeta(CopySourceFile, onMeta)
deliverCopyOutMeta(CopySourceDir, onMeta)
if len(got) != 2 || got[0] || !got[1] {
t.Fatalf("metadata callbacks = %v, want [false true]", got)
}
}
func TestCopyOutBoundaryError(t *testing.T) {
closing := make(chan struct{})
if err := copyOutBoundaryError(context.Background(), closing); err != nil {
t.Fatalf("open boundary error = %v, want nil", err)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
if err := copyOutBoundaryError(ctx, closing); !errors.Is(err, context.Canceled) {
t.Fatalf("cancelled boundary error = %v, want %v", err, context.Canceled)
}
close(closing)
if err := copyOutBoundaryError(context.Background(), closing); !errors.Is(err, ErrRuntimeClosed) {
t.Fatalf("closed boundary error = %v, want %v", err, ErrRuntimeClosed)
}
}