Allow snapshot to be created from empty local repo

Fixes #288
This commit is contained in:
Andrey Smirnov
2017-04-26 00:33:09 +03:00
parent d66185ca03
commit 8dc6a14766
6 changed files with 25 additions and 15 deletions
+8 -6
View File
@@ -53,11 +53,7 @@ func NewSnapshotFromRepository(name string, repo *RemoteRepo) (*Snapshot, error)
// NewSnapshotFromLocalRepo creates snapshot from current state of local repository // NewSnapshotFromLocalRepo creates snapshot from current state of local repository
func NewSnapshotFromLocalRepo(name string, repo *LocalRepo) (*Snapshot, error) { func NewSnapshotFromLocalRepo(name string, repo *LocalRepo) (*Snapshot, error) {
if repo.packageRefs == nil { snap := &Snapshot{
return nil, errors.New("local repo doesn't have packages")
}
return &Snapshot{
UUID: uuid.New(), UUID: uuid.New(),
Name: name, Name: name,
CreatedAt: time.Now(), CreatedAt: time.Now(),
@@ -65,7 +61,13 @@ func NewSnapshotFromLocalRepo(name string, repo *LocalRepo) (*Snapshot, error) {
SourceIDs: []string{repo.UUID}, SourceIDs: []string{repo.UUID},
Description: fmt.Sprintf("Snapshot from local repo %s", repo), Description: fmt.Sprintf("Snapshot from local repo %s", repo),
packageRefs: repo.packageRefs, packageRefs: repo.packageRefs,
}, nil }
if snap.packageRefs == nil {
snap.packageRefs = NewPackageRefList()
}
return snap, nil
} }
// NewSnapshotFromPackageList creates snapshot from PackageList // NewSnapshotFromPackageList creates snapshot from PackageList
+9 -3
View File
@@ -37,11 +37,17 @@ func (s *SnapshotSuite) TestNewSnapshotFromRepository(c *C) {
func (s *SnapshotSuite) TestNewSnapshotFromLocalRepo(c *C) { func (s *SnapshotSuite) TestNewSnapshotFromLocalRepo(c *C) {
localRepo := NewLocalRepo("lala", "hoorah!") localRepo := NewLocalRepo("lala", "hoorah!")
_, err := NewSnapshotFromLocalRepo("snap2", localRepo) snapshot, err := NewSnapshotFromLocalRepo("snap2", localRepo)
c.Check(err, ErrorMatches, "local repo doesn't have packages") 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) 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.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)
+3 -1
View File
@@ -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
View File
@@ -106,4 +106,3 @@ class CreateSnapshot9Test(BaseTest):
"aptly repo create local-repo", "aptly repo create local-repo",
] ]
runCmd = "aptly snapshot create snap9 from repo local-repo" runCmd = "aptly snapshot create snap9 from repo local-repo"
expectedCode = 1
-3
View File
@@ -105,9 +105,6 @@ class PublishSnapshotAPITest(APITest):
snapshot_name = self.random_name() snapshot_name = self.random_name()
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201) 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() d = self.random_name()
self.check_equal(self.upload("/api/files/" + d, self.check_equal(self.upload("/api/files/" + d,
"libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200) "libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200)
+5 -1
View File
@@ -97,8 +97,12 @@ class SnapshotsAPITestCreateFromRepo(APITest):
self.check_equal(self.post("/api/repos", json={"Name": repo_name}).status_code, 201) 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}) 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() d = self.random_name()
self.check_equal(self.upload("/api/files/" + d, self.check_equal(self.upload("/api/files/" + d,
"libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200) "libboost-program-options-dev_1.49.0.1_i386.deb").status_code, 200)