Example #1
0
func (s *MetadataSuite) TestFileMetadataSetStoredDefault(c *gc.C) {
	meta := filestorage.NewMetadata()
	c.Assert(meta.Stored(), gc.IsNil)
	meta.SetStored(nil)

	c.Check(meta.Stored(), gc.NotNil)
}
Example #2
0
func (s *MetadataSuite) TestFileMetadataDoc(c *gc.C) {
	meta := filestorage.NewMetadata(nil)
	meta.SetFile(10, "some sum", "SHA-1")
	doc := meta.Doc()

	c.Check(doc, gc.Equals, meta)
}
Example #3
0
func (s *MetadataSuite) TestFileMetadataSetStored(c *gc.C) {
	meta := filestorage.NewMetadata()
	timestamp := time.Now().UTC()
	meta.SetStored(&timestamp)

	c.Check(meta.Stored(), gc.Equals, &timestamp)
}
Example #4
0
func (s *MetadataSuite) TestFileMetadataSetStored(c *gc.C) {
	meta := filestorage.NewMetadata(nil)
	meta.SetFile(10, "some sum", "SHA-1")
	c.Assert(meta.Stored(), gc.Equals, false)

	meta.SetStored()
	c.Check(meta.Stored(), gc.Equals, true)
}
Example #5
0
func (s *MetadataSuite) TestFileMetadataNewMetadata(c *gc.C) {
	meta := filestorage.NewMetadata()

	c.Check(meta.ID(), gc.Equals, "")
	c.Check(meta.Size(), gc.Equals, int64(0))
	c.Check(meta.Checksum(), gc.Equals, "")
	c.Check(meta.ChecksumFormat(), gc.Equals, "")
	c.Check(meta.Stored(), gc.IsNil)
}
Example #6
0
// NewMetadata returns a new Metadata for a state backup archive.  Only
// the start time and the version are set.
func NewMetadata() *Metadata {
	return &Metadata{
		FileMetadata: filestorage.NewMetadata(),
		Started:      time.Now().UTC(),
		Origin: Origin{
			Version: version.Current,
		},
	}
}
Example #7
0
func (s *MetadataSuite) TestFileMetadataSetIDInitial(c *gc.C) {
	meta := filestorage.NewMetadata()
	meta.SetFileInfo(10, "some sum", "SHA-1")
	c.Assert(meta.ID(), gc.Equals, "")

	success := meta.SetID("some id")
	c.Check(success, gc.Equals, false)
	c.Check(meta.ID(), gc.Equals, "some id")
}
Example #8
0
func (s *WrapperSuite) SetUpTest(c *gc.C) {
	s.IsolationSuite.SetUpTest(c)

	var err error
	s.rawstor, err = filestorage.NewRawFileStorage(c.MkDir())
	c.Assert(err, gc.IsNil)
	s.metastor = filestorage.NewMetadataStorage()
	s.original = filestorage.NewMetadata(nil)
	s.original.SetFile(10, "", "")
}
Example #9
0
func (s *MetadataSuite) TestFileMetadataSetIDAlreadySetDifferent(c *gc.C) {
	meta := filestorage.NewMetadata()
	meta.SetFileInfo(10, "some sum", "SHA-1")
	success := meta.SetID("some id")
	c.Assert(success, gc.Equals, false)

	success = meta.SetID("another id")
	c.Check(success, gc.Equals, true)
	c.Check(meta.ID(), gc.Equals, "some id")
}
Example #10
0
// NewMetadata returns a new Metadata for a state backup archive.  Only
// the start time and the version are set.
func NewMetadata() *Metadata {
	return &Metadata{
		FileMetadata: filestorage.NewMetadata(),
		// TODO(fwereade): 2016-03-17 lp:1558657
		Started: time.Now().UTC(),
		Origin: Origin{
			Version: jujuversion.Current,
		},
	}
}
Example #11
0
func (s *MetadataSuite) TestFileMetadataSetIDAlreadySetSame(c *gc.C) {
	meta := filestorage.NewMetadata(nil)
	meta.SetFile(10, "some sum", "SHA-1")
	success := meta.SetID("some id")
	c.Assert(success, gc.Equals, false)

	success = meta.SetID("some id")
	c.Check(success, gc.Equals, true)
	c.Check(meta.ID(), gc.Equals, "some id")
}
Example #12
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)
	}
}
Example #13
0
func (s *MetadataSuite) TestFileMetadataNewMetadata(c *gc.C) {
	timestamp := time.Now().UTC()
	meta := filestorage.NewMetadata(&timestamp)

	c.Check(meta.ID(), gc.Equals, "")
	c.Check(meta.Size(), gc.Equals, int64(0))
	c.Check(meta.Checksum(), gc.Equals, "")
	c.Check(meta.ChecksumFormat(), gc.Equals, "")
	c.Check(meta.Timestamp(), gc.Equals, timestamp)
	c.Check(meta.Stored(), gc.Equals, false)
}
Example #14
0
func (s *MetadataSuite) TestFileMetadataSetFileInfo(c *gc.C) {
	meta := filestorage.NewMetadata()
	c.Assert(meta.Size(), gc.Equals, int64(0))
	c.Assert(meta.Checksum(), gc.Equals, "")
	c.Assert(meta.ChecksumFormat(), gc.Equals, "")
	c.Assert(meta.Stored(), gc.IsNil)
	meta.SetFileInfo(10, "some sum", "SHA-1")

	c.Check(meta.Size(), gc.Equals, int64(10))
	c.Check(meta.Checksum(), gc.Equals, "some sum")
	c.Check(meta.ChecksumFormat(), gc.Equals, "SHA-1")
	c.Check(meta.Stored(), gc.IsNil)
}
Example #15
0
func (s *MetadataStorageSuite) SetUpTest(c *gc.C) {
	s.IsolationSuite.SetUpTest(c)
	s.original = filestorage.NewMetadata(nil)
	s.original.SetFile(0, "", "")
}
Example #16
0
func (s *MetadataSuite) TestFileMetadataNewMetadataDefaultTimestamp(c *gc.C) {
	meta := filestorage.NewMetadata(nil)

	c.Check(meta.ID(), gc.Equals, "")
	c.Check(meta.Timestamp(), gc.NotNil)
}
Example #17
0
// NewMetadata returns a new Metadata for a state backup archive.  The
// current date/time is used for the timestamp and the default checksum
// format is used.  ID is not set.  That is left up to the persistence
// layer.  Stored is set as false.  "notes" may be empty, but
// everything else should be provided.
func NewMetadata(origin Origin, notes string, started *time.Time) *Metadata {
	raw := filestorage.NewMetadata(started)
	metadata := Metadata{*raw, nil, origin, notes}
	return &metadata
}
Example #18
0
func (s *WrapperSuite) metadata() filestorage.Metadata {
	meta := filestorage.NewMetadata()
	meta.SetFileInfo(10, "", "")
	return meta
}