Snapshot creation from package list.

This commit is contained in:
Andrey Smirnov
2014-01-12 13:05:27 +04:00
parent c0b41a7e96
commit 9ca005147c
2 changed files with 30 additions and 0 deletions

18
debian/snapshot.go vendored
View File

@@ -46,6 +46,24 @@ func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error)
}, nil
}
// NewSnapshotFromPackageList creates snapshot from PackageList
func NewSnapshotFromPackageList(name string, sources []*Snapshot, list *PackageList, description string) *Snapshot {
sourceUUIDs := make([]string, len(sources))
for i := range sources {
sourceUUIDs[i] = sources[i].UUID
}
return &Snapshot{
UUID: uuid.New(),
Name: name,
CreatedAt: time.Now(),
SourceKind: "snapshot",
SourceIDs: sourceUUIDs,
Description: description,
packageRefs: NewPackageRefListFromPackageList(list),
}
}
// String returns string representation of snapshot
func (s *Snapshot) String() string {
return fmt.Sprintf("[%s]: %s", s.Name, s.Description)

View File

@@ -24,12 +24,24 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
c.Check(snapshot.Name, Equals, "snap1")
c.Check(snapshot.NumPackages(), Equals, 3)
c.Check(snapshot.RefList().Len(), Equals, 3)
c.Check(snapshot.SourceKind, Equals, "repo")
c.Check(snapshot.SourceIDs, DeepEquals, []string{s.repo.UUID})
s.repo.packageRefs = nil
_, err := NewSnapshotFromRepository("snap2", s.repo)
c.Check(err, ErrorMatches, ".*not updated")
}
func (s *SnapshotSuite) TestNewSnapshotFromPackageList(c *C) {
snap, _ := NewSnapshotFromRepository("snap1", s.repo)
snapshot := NewSnapshotFromPackageList("snap2", []*Snapshot{snap}, s.list, "Pulled")
c.Check(snapshot.Name, Equals, "snap2")
c.Check(snapshot.NumPackages(), Equals, 3)
c.Check(snapshot.SourceKind, Equals, "snapshot")
c.Check(snapshot.SourceIDs, DeepEquals, []string{snap.UUID})
}
func (s *SnapshotSuite) TestKey(c *C) {
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
c.Assert(len(snapshot.Key()), Equals, 37)