Exemplo n.º 1
0
func (s *WrapperSuite) TestFileStorageAddIDAlreadySet(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	s.original.SetID("eggs")
	_, err := stor.Add(s.original, nil)

	c.Check(err, gc.ErrorMatches, "ID already set .*")
}
Exemplo n.º 2
0
func (s *WrapperSuite) TestFileStorageListEmpty(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	list, err := stor.List()
	c.Check(err, gc.IsNil)

	c.Check(list, gc.HasLen, 0)
}
Exemplo n.º 3
0
func (s *WrapperSuite) SetUpTest(c *gc.C) {
	s.IsolationSuite.SetUpTest(c)

	s.rawstor = &FakeRawFileStorage{}
	s.metastor = &FakeMetadataStorage{}
	s.stor = filestorage.NewFileStorage(s.metastor, s.rawstor)
}
Exemplo n.º 4
0
func (s *WrapperSuite) TestFileStorageMetadata(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	id, err := stor.Add(s.original, nil)
	c.Assert(err, gc.IsNil)
	meta, err := stor.Metadata(id)
	c.Check(err, gc.IsNil)

	c.Check(meta, gc.DeepEquals, s.original)
}
Exemplo n.º 5
0
// NewStorage returns a new FileStorage to use for storing backup
// archives (and metadata).
func NewStorage(st DB) filestorage.FileStorage {
	envUUID := st.EnvironTag().Id()
	db := st.MongoSession().DB(storageDBName)
	dbWrap := newStorageDBWrapper(db, storageMetaName, envUUID)
	defer dbWrap.Close()

	files := newFileStorage(dbWrap, backupStorageRoot)
	docs := newMetadataStorage(dbWrap)
	return filestorage.NewFileStorage(docs, files)
}
Exemplo n.º 6
0
func (s *WrapperSuite) TestClose(c *gc.C) {
	metaStor := &FakeMetadataStorage{}
	fileStor := &FakeRawFileStorage{}
	stor := filestorage.NewFileStorage(metaStor, fileStor)
	err := stor.Close()
	c.Assert(err, gc.IsNil)

	c.Check(metaStor.calls, gc.DeepEquals, []string{"Close"})
	c.Check(fileStor.calls, gc.DeepEquals, []string{"Close"})
}
Exemplo n.º 7
0
func (s *WrapperSuite) TestFileStorageListOne(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	id, err := stor.Add(s.original, nil)
	c.Assert(err, gc.IsNil)
	list, err := stor.List()
	c.Check(err, gc.IsNil)

	c.Check(list, gc.HasLen, 1)
	c.Assert(list[0], gc.NotNil)
	c.Check(list[0].ID(), gc.Equals, id)
}
Exemplo n.º 8
0
func (s *WrapperSuite) TestFileStorageGet(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	data := bytes.NewBufferString("spam")
	id, err := stor.Add(s.original, data)
	c.Assert(err, gc.IsNil)
	meta, file, err := stor.Get(id)
	c.Check(err, gc.IsNil)
	content, err := ioutil.ReadAll(file)

	c.Check(meta, gc.DeepEquals, s.original)
	c.Check(string(content), gc.Equals, "spam")
}
Exemplo n.º 9
0
func (s *WrapperSuite) TestFileStorageRemove(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	id, err := stor.Add(s.original, nil)
	c.Assert(err, gc.IsNil)
	_, err = stor.Metadata(id)
	c.Assert(err, gc.IsNil)

	err = stor.Remove(id)
	c.Check(err, gc.IsNil)
	_, err = stor.Metadata(id)
	c.Check(err, gc.NotNil)
}
Exemplo n.º 10
0
func (s *WrapperSuite) TestFileStorageAddFileFailureDropsMetadata(c *gc.C) {
	original := s.metadata()
	failure := errors.New("failed!")
	raw := &FakeRawFileStorage{err: failure}
	stor := filestorage.NewFileStorage(s.metastor, raw)
	_, err := stor.Add(original, &bytes.Buffer{})

	c.Assert(errors.Cause(err), gc.Equals, failure)

	metalist, metaErr := s.metastor.ListMetadata()
	c.Assert(metaErr, gc.IsNil)
	c.Check(metalist, gc.HasLen, 0)
	c.Check(original.ID(), gc.Equals, "")
}
Exemplo n.º 11
0
func (s *WrapperSuite) TestFileStorageListTwo(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	original1 := filestorage.NewMetadata(nil)
	id1, err := stor.Add(original1, nil)
	c.Assert(err, gc.IsNil)
	original2 := filestorage.NewMetadata(nil)
	id2, err := stor.Add(original2, nil)
	c.Assert(err, gc.IsNil)
	list, err := stor.List()
	c.Check(err, gc.IsNil)

	c.Assert(list, gc.HasLen, 2)
	c.Assert(list[0], gc.NotNil)
	c.Assert(list[1], gc.NotNil)
	if list[0].ID() == id1 {
		c.Check(list[1].ID(), gc.Equals, id2)
	} else {
		c.Check(list[1].ID(), gc.Equals, id1)
	}
}
Exemplo n.º 12
0
func (s *WrapperSuite) TestFileStorageSetFile(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)
	id, err := stor.Add(s.original, nil)
	c.Assert(err, gc.IsNil)

	_, _, err = stor.Get(id)
	c.Assert(err, gc.NotNil)
	meta, err := stor.Metadata(id)
	c.Assert(err, gc.IsNil)
	c.Check(meta.Stored(), gc.Equals, false)

	data := bytes.NewBufferString("spam")
	err = stor.SetFile(id, data)
	meta, file, err := stor.Get(id)
	c.Assert(err, gc.IsNil)
	content, err := ioutil.ReadAll(file)
	c.Assert(err, gc.IsNil)
	c.Check(meta.Stored(), gc.Equals, true)
	c.Check(string(content), gc.Equals, "spam")
}
Exemplo n.º 13
0
// NewBackupsStorage returns a new FileStorage to use for storing backup
// archives (and metadata).
func NewBackupsStorage(st *State, envStor storage.Storage) filestorage.FileStorage {
	files := newBackupFileStorage(envStor, backupStorageRoot)
	docs := newBackupMetadataStorage(st)
	return filestorage.NewFileStorage(docs, files)
}
Exemplo n.º 14
0
func (s *WrapperSuite) TestFileStorageNewFileStorage(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)

	c.Check(stor, gc.NotNil)
}