-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock_test.go
89 lines (75 loc) · 2.32 KB
/
mock_test.go
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gsprotocol
import (
"context"
"io"
"cloud.google.com/go/storage"
)
var bucketMockNotFount = &bucketHandleMock{
objectFunc: func(mock *bucketHandleMock, name string) *objectHandleMock {
return objectMockNotFound
},
}
var objectMockNotFound = &objectHandleMock{
attrFunc: func(ctx context.Context, mock *objectHandleMock) (*storage.ObjectAttrs, error) {
return nil, storage.ErrObjectNotExist
},
newReaderFunc: func(ctx context.Context, mock *objectHandleMock) (storage.ReaderObjectAttrs, io.ReadCloser, error) {
return storage.ReaderObjectAttrs{}, nil, storage.ErrObjectNotExist
},
generationFunc: func(mock *objectHandleMock, gen int64) *objectHandleMock {
return mock
},
}
type storageClientMock struct {
bucketFunc func(mock *storageClientMock, name string) *bucketHandleMock
}
func (c *storageClientMock) Bucket(name string) bucketHandle {
if c.bucketFunc == nil {
panic("unexpected call of Bucket")
}
return c.bucketFunc(c, name)
}
type bucketHandleMock struct {
objectFunc func(mock *bucketHandleMock, name string) *objectHandleMock
}
func (h *bucketHandleMock) Object(name string) objectHandle {
if h.objectFunc == nil {
panic("unexpected call of Object")
}
return h.objectFunc(h, name)
}
type objectHandleMock struct {
generation int64
attrFunc func(ctx context.Context, mock *objectHandleMock) (attrs *storage.ObjectAttrs, err error)
newReaderFunc func(ctx context.Context, mock *objectHandleMock) (storage.ReaderObjectAttrs, io.ReadCloser, error)
generationFunc func(mock *objectHandleMock, gen int64) *objectHandleMock
}
func (h *objectHandleMock) Attrs(ctx context.Context) (attrs *storage.ObjectAttrs, err error) {
if h.attrFunc == nil {
panic("unexpected call of Attrs")
}
return h.attrFunc(ctx, h)
}
func (h *objectHandleMock) NewReader(ctx context.Context) (storageReader, error) {
attrs, reader, err := h.newReaderFunc(ctx, h)
if err != nil {
return nil, err
}
return &storageReaderMock{
ReadCloser: reader,
attrs: attrs,
}, nil
}
func (h *objectHandleMock) Generation(gen int64) objectHandle {
if h.generationFunc == nil {
panic("unexpected call of Generation")
}
return h.generationFunc(h, gen)
}
type storageReaderMock struct {
io.ReadCloser
attrs storage.ReaderObjectAttrs
}
func (r *storageReaderMock) Attrs() storage.ReaderObjectAttrs {
return r.attrs
}