Skip to content

Commit

Permalink
Merge pull request #555 from smira/288-empty-repo-snapshot
Browse files Browse the repository at this point in the history
Allow snapshot to be created from empty local repo
  • Loading branch information
smira committed Apr 25, 2017
2 parents d66185c + 8dc6a14 commit a245b72
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
14 changes: 8 additions & 6 deletions deb/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error)

// NewSnapshotFromLocalRepo creates snapshot from current state of local repository
func NewSnapshotFromLocalRepo(name string, repo *LocalRepo) (*Snapshot, error) {
if repo.packageRefs == nil {
return nil, errors.New("local repo doesn't have packages")
}

return &Snapshot{
snap := &Snapshot{
UUID: uuid.New(),
Name: name,
CreatedAt: time.Now(),
SourceKind: "local",
SourceIDs: []string{repo.UUID},
Description: fmt.Sprintf("Snapshot from local repo %s", repo),
packageRefs: repo.packageRefs,
}, nil
}

if snap.packageRefs == nil {
snap.packageRefs = NewPackageRefList()
}

return snap, nil
}

// NewSnapshotFromPackageList creates snapshot from PackageList
Expand Down
12 changes: 9 additions & 3 deletions deb/snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
func (s *SnapshotSuite) TestNewSnapshotFromLocalRepo(c *C) {
localRepo := NewLocalRepo("lala", "hoorah!")

_, err := NewSnapshotFromLocalRepo("snap2", localRepo)
c.Check(err, ErrorMatches, "local repo doesn't have packages")
snapshot, err := NewSnapshotFromLocalRepo("snap2", localRepo)
c.Assert(err, IsNil)
c.Check(snapshot.Name, Equals, "snap2")
c.Check(snapshot.NumPackages(), Equals, 0)
c.Check(snapshot.RefList().Len(), Equals, 0)
c.Check(snapshot.SourceKind, Equals, "local")
c.Check(snapshot.SourceIDs, DeepEquals, []string{localRepo.UUID})

localRepo.UpdateRefList(s.reflist)
snapshot, _ := NewSnapshotFromLocalRepo("snap1", localRepo)
snapshot, err = NewSnapshotFromLocalRepo("snap1", localRepo)
c.Assert(err, IsNil)
c.Check(snapshot.Name, Equals, "snap1")
c.Check(snapshot.NumPackages(), Equals, 3)
c.Check(snapshot.RefList().Len(), Equals, 3)
Expand Down
4 changes: 3 additions & 1 deletion system/t05_snapshot/CreateSnapshot9Test_gold
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ERROR: unable to create snapshot: local repo doesn't have packages

Snapshot snap9 successfully created.
You can run 'aptly publish snapshot snap9' to publish snapshot as Debian repository.
1 change: 0 additions & 1 deletion system/t05_snapshot/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ class CreateSnapshot9Test(BaseTest):
"aptly repo create local-repo",
]
runCmd = "aptly snapshot create snap9 from repo local-repo"
expectedCode = 1
3 changes: 0 additions & 3 deletions system/t12_api/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ def check(self):
snapshot_name = self.random_name()
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201)

resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
self.check_equal(resp.status_code, 400)

d = self.random_name()
self.check_equal(self.upload("/api/files/" + d,
"libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200)
Expand Down
6 changes: 5 additions & 1 deletion system/t12_api/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ def check(self):
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201)

resp = self.post("/api/repos/" + repo_name + '/snapshots', json={'Name': snapshot_name})
self.check_equal(resp.status_code, 400)
self.check_equal(resp.status_code, 201)
self.check_equal([],
self.get("/api/snapshots/" + snapshot_name + "/packages", params={"format": "details"}).json())


snapshot_name = self.random_name()
d = self.random_name()
self.check_equal(self.upload("/api/files/" + d,
"libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200)
Expand Down

0 comments on commit a245b72

Please sign in to comment.