mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-05 05:20:34 +00:00
Start of snapshot work.
This commit is contained in:
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Snapshot is immutable state of repository: list of packages
|
||||
type Snapshot struct {
|
||||
// Persisten internal ID
|
||||
UUID string
|
||||
// Human-readable name
|
||||
Name string
|
||||
// Date of creation
|
||||
CreatedAt time.Time
|
||||
|
||||
// Source: kind + ID
|
||||
SourceKind string
|
||||
SourceIDs []string
|
||||
// Description of how snapshot was created
|
||||
Description string
|
||||
|
||||
packageRefs *PackageRefList
|
||||
}
|
||||
|
||||
// NewSnapshotFromRepository creates snapshot from current state of repository
|
||||
func NewSnapshotFromRepository(name string, repo *RemoteRepo) *Snapshot {
|
||||
if repo.packageRefs == nil {
|
||||
panic("repo.packageRefs == nil")
|
||||
}
|
||||
|
||||
return &Snapshot{
|
||||
UUID: uuid.New(),
|
||||
Name: name,
|
||||
CreatedAt: time.Now(),
|
||||
SourceKind: "repo",
|
||||
SourceIDs: []string{repo.UUID},
|
||||
Description: fmt.Sprintf("Snapshot from mirror %s", repo),
|
||||
packageRefs: repo.packageRefs,
|
||||
}
|
||||
}
|
||||
|
||||
// NumPackages returns number of packages in snapshot
|
||||
func (s *Snapshot) NumPackages() int {
|
||||
return s.packageRefs.Len()
|
||||
}
|
||||
|
||||
// Key is a unique id in DB
|
||||
func (s *Snapshot) Key() []byte {
|
||||
return []byte("S" + s.UUID)
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
package debian
|
||||
|
||||
import (
|
||||
. "launchpad.net/gocheck"
|
||||
)
|
||||
|
||||
type SnapshotSuite struct {
|
||||
PackageListMixinSuite
|
||||
repo *RemoteRepo
|
||||
}
|
||||
|
||||
var _ = Suite(&SnapshotSuite{})
|
||||
|
||||
func (s *SnapshotSuite) SetUpTest(c *C) {
|
||||
s.SetUpPackages()
|
||||
s.repo, _ = NewRemoteRepo("yandex", "http://mirror.yandex.ru/debian/", "squeeze", []string{"main"}, []string{})
|
||||
s.repo.packageRefs = s.reflist
|
||||
}
|
||||
|
||||
func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
|
||||
snapshot := NewSnapshotFromRepository("snap1", s.repo)
|
||||
c.Check(snapshot.Name, Equals, "snap1")
|
||||
c.Check(snapshot.NumPackages(), Equals, 3)
|
||||
|
||||
s.repo.packageRefs = nil
|
||||
c.Check(func() { NewSnapshotFromRepository("snap2", s.repo) }, PanicMatches, "repo.packageRefs == nil")
|
||||
}
|
||||
|
||||
func (s *SnapshotSuite) TestKey(c *C) {
|
||||
snapshot := NewSnapshotFromRepository("snap1", s.repo)
|
||||
c.Assert(len(snapshot.Key()), Equals, 37)
|
||||
c.Assert(snapshot.Key()[0], Equals, byte('S'))
|
||||
}
|
||||
Reference in New Issue
Block a user