1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
4
package filestorage_test
9
"github.com/juju/errors"
10
jc "github.com/juju/testing/checkers"
11
gc "gopkg.in/check.v1"
13
"github.com/juju/utils/filestorage"
16
// FakeMetadataStorage is used as a DocStorage and MetadataStorage for
18
type FakeMetadataStorage struct {
22
meta filestorage.Metadata
23
metaList []filestorage.Metadata
27
metaArg filestorage.Metadata
30
// Check verfies the state of the fake.
31
func (s *FakeMetadataStorage) Check(c *gc.C, id string, meta filestorage.Metadata, calls ...string) {
32
c.Check(s.calls, jc.DeepEquals, calls)
33
c.Check(s.idArg, gc.Equals, id)
34
c.Check(s.metaArg, gc.Equals, meta)
37
func (s *FakeMetadataStorage) Doc(id string) (filestorage.Document, error) {
38
s.calls = append(s.calls, "Doc")
46
func (s *FakeMetadataStorage) ListDocs() ([]filestorage.Document, error) {
47
s.calls = append(s.calls, "ListDoc")
51
var docs []filestorage.Document
52
for _, doc := range s.metaList {
53
docs = append(docs, doc)
58
func (s *FakeMetadataStorage) AddDoc(doc filestorage.Document) (string, error) {
59
s.calls = append(s.calls, "AddDoc")
60
meta, err := filestorage.Convert(doc)
62
return "", errors.Trace(err)
68
func (s *FakeMetadataStorage) RemoveDoc(id string) error {
69
s.calls = append(s.calls, "RemoveDoc")
74
func (s *FakeMetadataStorage) Close() error {
75
s.calls = append(s.calls, "Close")
79
func (s *FakeMetadataStorage) Metadata(id string) (filestorage.Metadata, error) {
80
s.calls = append(s.calls, "Metadata")
88
func (s *FakeMetadataStorage) ListMetadata() ([]filestorage.Metadata, error) {
89
s.calls = append(s.calls, "ListMetadata")
93
return s.metaList, nil
96
func (s *FakeMetadataStorage) AddMetadata(meta filestorage.Metadata) (string, error) {
97
s.calls = append(s.calls, "AddMetadata")
105
func (s *FakeMetadataStorage) RemoveMetadata(id string) error {
106
s.calls = append(s.calls, "RemoveMetadata")
111
func (s *FakeMetadataStorage) SetStored(id string) error {
112
s.calls = append(s.calls, "SetStored")
117
// FakeRawFileStorage is used in testing as a RawFileStorage.
118
type FakeRawFileStorage struct {
129
// Check verfies the state of the fake.
130
func (s *FakeRawFileStorage) Check(c *gc.C, id string, file io.Reader, size int64, calls ...string) {
131
c.Check(s.calls, jc.DeepEquals, calls)
132
c.Check(s.idArg, gc.Equals, id)
133
c.Check(s.fileArg, gc.Equals, file)
134
c.Check(s.sizeArg, gc.Equals, size)
137
// CheckNotUsed verifies that the fake was not used.
138
func (s *FakeRawFileStorage) CheckNotUsed(c *gc.C) {
139
s.Check(c, "", nil, 0)
142
func (s *FakeRawFileStorage) File(id string) (io.ReadCloser, error) {
143
s.calls = append(s.calls, "File")
151
func (s *FakeRawFileStorage) AddFile(id string, file io.Reader, size int64) error {
152
s.calls = append(s.calls, "AddFile")
159
func (s *FakeRawFileStorage) RemoveFile(id string) error {
160
s.calls = append(s.calls, "RemoveFile")
165
func (s *FakeRawFileStorage) Close() error {
166
s.calls = append(s.calls, "Close")