예제 #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 .*")
}
예제 #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)
}
예제 #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)
}
예제 #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)
}
예제 #5
0
파일: storage.go 프로젝트: imoapps/juju
// 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)
}
예제 #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"})
}
예제 #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)
}
예제 #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")
}
예제 #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)
}
예제 #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, "")
}
예제 #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)
	}
}
예제 #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")
}
예제 #13
0
파일: backups.go 프로젝트: kapilt/juju
// 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)
}
예제 #14
0
func (s *WrapperSuite) TestFileStorageNewFileStorage(c *gc.C) {
	stor := filestorage.NewFileStorage(s.metastor, s.rawstor)

	c.Check(stor, gc.NotNil)
}