mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-07-26 13:47:40 +00:00
Add SnapshotCollection.ByUUID.
This commit is contained in:
Vendored
+10
@@ -179,6 +179,16 @@ func (collection *SnapshotCollection) ByName(name string) (*Snapshot, error) {
|
|||||||
return nil, fmt.Errorf("snapshot with name %s not found", name)
|
return nil, fmt.Errorf("snapshot with name %s not found", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ByUUID looks up snapshot by UUID
|
||||||
|
func (collection *SnapshotCollection) ByUUID(uuid string) (*Snapshot, error) {
|
||||||
|
for _, s := range collection.list {
|
||||||
|
if s.UUID == uuid {
|
||||||
|
return s, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("snapshot with uuid %s not found", uuid)
|
||||||
|
}
|
||||||
|
|
||||||
// ForEach runs method for each snapshot
|
// ForEach runs method for each snapshot
|
||||||
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
func (collection *SnapshotCollection) ForEach(handler func(*Snapshot) error) error {
|
||||||
var err error
|
var err error
|
||||||
|
|||||||
Vendored
+5
-1
@@ -93,7 +93,7 @@ func (s *SnapshotCollectionSuite) TearDownTest(c *C) {
|
|||||||
s.db.Close()
|
s.db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SnapshotCollectionSuite) TestAddByName(c *C) {
|
func (s *SnapshotCollectionSuite) TestAddByNameByUUID(c *C) {
|
||||||
snapshot, err := s.collection.ByName("snap1")
|
snapshot, err := s.collection.ByName("snap1")
|
||||||
c.Assert(err, ErrorMatches, "*.not found")
|
c.Assert(err, ErrorMatches, "*.not found")
|
||||||
|
|
||||||
@@ -110,6 +110,10 @@ func (s *SnapshotCollectionSuite) TestAddByName(c *C) {
|
|||||||
snapshot, err = collection.ByName("snap1")
|
snapshot, err = collection.ByName("snap1")
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
c.Assert(snapshot.String(), Equals, s.snapshot1.String())
|
c.Assert(snapshot.String(), Equals, s.snapshot1.String())
|
||||||
|
|
||||||
|
snapshot, err = collection.ByUUID(s.snapshot1.UUID)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
c.Assert(snapshot.String(), Equals, s.snapshot1.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SnapshotCollectionSuite) TestUpdateLoadComplete(c *C) {
|
func (s *SnapshotCollectionSuite) TestUpdateLoadComplete(c *C) {
|
||||||
|
|||||||
Reference in New Issue
Block a user