forked from cloudfoundry/bosh-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_blobstore.go
88 lines (67 loc) · 1.77 KB
/
fake_blobstore.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
package fakes
import (
boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
)
type FakeBlobstore struct {
GetBlobIDs []string
GetFingerprints []boshcrypto.Digest
GetFileName string
GetFileNames []string
GetError error
GetErrs []error
CleanUpFileName string
CleanUpErr error
DeleteBlobID string
DeleteErr error
CreateFileNames []string
CreateBlobID string
CreateBlobIDs []string
CreateErr error
CreateErrs []error
CreateCallBack func()
ValidateError error
}
func NewFakeBlobstore() *FakeBlobstore {
return &FakeBlobstore{}
}
func (bs *FakeBlobstore) Get(blobID string, fingerprint boshcrypto.Digest) (string, error) {
bs.GetBlobIDs = append(bs.GetBlobIDs, blobID)
bs.GetFingerprints = append(bs.GetFingerprints, fingerprint)
fileName, err := bs.GetFileName, bs.GetError
if len(bs.GetFileNames) > 0 {
fileName = bs.GetFileNames[0]
bs.GetFileNames = bs.GetFileNames[1:]
}
if len(bs.GetErrs) > 0 {
err = bs.GetErrs[0]
bs.GetErrs = bs.GetErrs[1:]
}
return fileName, err
}
func (bs *FakeBlobstore) CleanUp(fileName string) error {
bs.CleanUpFileName = fileName
return bs.CleanUpErr
}
func (bs *FakeBlobstore) Delete(blobId string) error {
bs.DeleteBlobID = blobId
return bs.DeleteErr
}
func (bs *FakeBlobstore) Create(fileName string) (string, error) {
bs.CreateFileNames = append(bs.CreateFileNames, fileName)
if bs.CreateCallBack != nil {
bs.CreateCallBack()
}
blobID, err := bs.CreateBlobID, bs.CreateErr
if len(bs.CreateBlobIDs) > 0 {
blobID = bs.CreateBlobIDs[0]
bs.CreateBlobIDs = bs.CreateBlobIDs[1:]
}
if len(bs.CreateErrs) > 0 {
err = bs.CreateErrs[0]
bs.CreateErrs = bs.CreateErrs[1:]
}
return blobID, err
}
func (bs *FakeBlobstore) Validate() error {
return bs.ValidateError
}