mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Snapshot creation from package list.
This commit is contained in:
18
debian/snapshot.go
vendored
18
debian/snapshot.go
vendored
@@ -46,6 +46,24 @@ func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error)
|
|||||||
}, nil
|
}, 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
|
// String returns string representation of snapshot
|
||||||
func (s *Snapshot) String() string {
|
func (s *Snapshot) String() string {
|
||||||
return fmt.Sprintf("[%s]: %s", s.Name, s.Description)
|
return fmt.Sprintf("[%s]: %s", s.Name, s.Description)
|
||||||
|
|||||||
12
debian/snapshot_test.go
vendored
12
debian/snapshot_test.go
vendored
@@ -24,12 +24,24 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
|
|||||||
c.Check(snapshot.Name, Equals, "snap1")
|
c.Check(snapshot.Name, Equals, "snap1")
|
||||||
c.Check(snapshot.NumPackages(), Equals, 3)
|
c.Check(snapshot.NumPackages(), Equals, 3)
|
||||||
c.Check(snapshot.RefList().Len(), 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
|
s.repo.packageRefs = nil
|
||||||
_, err := NewSnapshotFromRepository("snap2", s.repo)
|
_, err := NewSnapshotFromRepository("snap2", s.repo)
|
||||||
c.Check(err, ErrorMatches, ".*not updated")
|
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) {
|
func (s *SnapshotSuite) TestKey(c *C) {
|
||||||
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
|
snapshot, _ := NewSnapshotFromRepository("snap1", s.repo)
|
||||||
c.Assert(len(snapshot.Key()), Equals, 37)
|
c.Assert(len(snapshot.Key()), Equals, 37)
|
||||||
|
|||||||
Reference in New Issue
Block a user