mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
aptly snapshot drop with system tests.
This commit is contained in:
@@ -504,16 +504,41 @@ func aptlySnapshotDrop(cmd *commander.Command, args []string) error {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
force := cmd.Flag.Lookup("force").Value.Get().(bool)
|
||||
if !force {
|
||||
// check for snapshots using this
|
||||
publishedRepoCollection := debian.NewPublishedRepoCollection(context.database)
|
||||
published := publishedRepoCollection.BySnapshot(snapshot)
|
||||
|
||||
if len(published) > 0 {
|
||||
fmt.Printf("Snapshot `%s` is published currently:\n", snapshot.Name)
|
||||
for _, repo := range published {
|
||||
err = publishedRepoCollection.LoadComplete(repo, snapshotCollection)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to load published: %s", err)
|
||||
}
|
||||
fmt.Printf(" * %s\n", repo)
|
||||
}
|
||||
|
||||
return fmt.Errorf("unable to drop: snapshot is published")
|
||||
}
|
||||
|
||||
// check for published repos
|
||||
force := cmd.Flag.Lookup("force").Value.Get().(bool)
|
||||
if !force {
|
||||
snapshots := snapshotCollection.BySnapshotSource(snapshot)
|
||||
if len(snapshots) > 0 {
|
||||
fmt.Printf("Snapshot `%s` was used as a source in following snapshots:\n", snapshot.Name)
|
||||
for _, snap := range snapshots {
|
||||
fmt.Printf(" * %s\n", snap)
|
||||
}
|
||||
|
||||
// drop
|
||||
return fmt.Errorf("won't delete snapshot that was used as source for other snapshots, use -force to override")
|
||||
}
|
||||
}
|
||||
|
||||
_ = snapshot
|
||||
err = snapshotCollection.Drop(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to drop: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Snapshot `%s` has been dropped.\n", snapshot.Name)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,3 +9,6 @@ aptly mirror update wheezy-contrib
|
||||
aptly mirror update wheezy-non-free
|
||||
aptly mirror update wheezy-updates
|
||||
aptly mirror update wheezy-backports
|
||||
|
||||
aptly mirror create gnuplot-maverick http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick
|
||||
aptly mirror update gnuplot-maverick
|
||||
|
||||
1
system/t05_snapshot/DropSnapshot1Test_gold
Normal file
1
system/t05_snapshot/DropSnapshot1Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
Snapshot `snap1` has been dropped.
|
||||
1
system/t05_snapshot/DropSnapshot1Test_snapshot_show
Normal file
1
system/t05_snapshot/DropSnapshot1Test_snapshot_show
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: unable to show: snapshot with name snap1 not found
|
||||
3
system/t05_snapshot/DropSnapshot2Test_gold
Normal file
3
system/t05_snapshot/DropSnapshot2Test_gold
Normal file
@@ -0,0 +1,3 @@
|
||||
Snapshot `snap1` was used as a source in following snapshots:
|
||||
* [snap2]: Merged from sources: 'snap1'
|
||||
ERROR: won't delete snapshot that was used as source for other snapshots, use -force to override
|
||||
1
system/t05_snapshot/DropSnapshot3Test_gold
Normal file
1
system/t05_snapshot/DropSnapshot3Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
Snapshot `snap1` has been dropped.
|
||||
1
system/t05_snapshot/DropSnapshot3Test_snapshot_show
Normal file
1
system/t05_snapshot/DropSnapshot3Test_snapshot_show
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: unable to show: snapshot with name snap1 not found
|
||||
3
system/t05_snapshot/DropSnapshot4Test_gold
Normal file
3
system/t05_snapshot/DropSnapshot4Test_gold
Normal file
@@ -0,0 +1,3 @@
|
||||
Snapshot `snap1` is published currently:
|
||||
* ./maverick (main) [amd64, i386] publishes [snap1]: Snapshot from mirror [gnuplot-maverick]: http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick
|
||||
ERROR: unable to drop: snapshot is published
|
||||
3
system/t05_snapshot/DropSnapshot5Test_gold
Normal file
3
system/t05_snapshot/DropSnapshot5Test_gold
Normal file
@@ -0,0 +1,3 @@
|
||||
Snapshot `snap1` is published currently:
|
||||
* ./maverick (main) [amd64, i386] publishes [snap1]: Snapshot from mirror [gnuplot-maverick]: http://ppa.launchpad.net/gladky-anton/gnuplot/ubuntu/ maverick
|
||||
ERROR: unable to drop: snapshot is published
|
||||
1
system/t05_snapshot/DropSnapshot6Test_gold
Normal file
1
system/t05_snapshot/DropSnapshot6Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
ERROR: unable to drop: snapshot with name no-such-snapshot not found
|
||||
1
system/t05_snapshot/DropSnapshot7Test_gold
Normal file
1
system/t05_snapshot/DropSnapshot7Test_gold
Normal file
@@ -0,0 +1 @@
|
||||
Snapshot `snap1` has been dropped.
|
||||
@@ -9,3 +9,4 @@ from .verify import *
|
||||
from .pull import *
|
||||
from .diff import *
|
||||
from .merge import *
|
||||
from .drop import *
|
||||
|
||||
94
system/t05_snapshot/drop.py
Normal file
94
system/t05_snapshot/drop.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from lib import BaseTest
|
||||
|
||||
|
||||
class DropSnapshot1Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: just drop
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixtureCmds = ["aptly snapshot create snap1 from mirror wheezy-non-free"]
|
||||
runCmd = "aptly snapshot drop snap1"
|
||||
|
||||
def check(self):
|
||||
self.check_output()
|
||||
self.check_cmd_output("aptly snapshot show snap1", "snapshot_show", expected_code=1)
|
||||
|
||||
|
||||
class DropSnapshot2Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: used as source
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror wheezy-non-free",
|
||||
"aptly snapshot merge snap2 snap1",
|
||||
]
|
||||
runCmd = "aptly snapshot drop snap1"
|
||||
expectedCode = 1
|
||||
|
||||
|
||||
class DropSnapshot3Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: -force
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror wheezy-non-free",
|
||||
"aptly snapshot merge snap2 snap1",
|
||||
]
|
||||
runCmd = "aptly snapshot drop -force snap1"
|
||||
|
||||
def check(self):
|
||||
self.check_output()
|
||||
self.check_cmd_output("aptly snapshot show snap1", "snapshot_show", expected_code=1)
|
||||
|
||||
|
||||
class DropSnapshot4Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: already published
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixturePool = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror gnuplot-maverick",
|
||||
"aptly publish snapshot snap1"
|
||||
]
|
||||
runCmd = "aptly snapshot drop snap1"
|
||||
expectedCode = 1
|
||||
|
||||
|
||||
class DropSnapshot5Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: already published with -force
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixturePool = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror gnuplot-maverick",
|
||||
"aptly publish snapshot snap1"
|
||||
]
|
||||
runCmd = "aptly snapshot drop --force snap1"
|
||||
expectedCode = 1
|
||||
|
||||
|
||||
class DropSnapshot6Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: no such snapshot
|
||||
"""
|
||||
fixtureDB = True
|
||||
runCmd = "aptly snapshot drop no-such-snapshot"
|
||||
expectedCode = 1
|
||||
|
||||
|
||||
class DropSnapshot7Test(BaseTest):
|
||||
"""
|
||||
drop snapshot: publish, drop publish, drop snapshot
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixturePool = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror gnuplot-maverick",
|
||||
"aptly publish snapshot snap1",
|
||||
"aptly publish drop maverick",
|
||||
]
|
||||
runCmd = "aptly snapshot drop snap1"
|
||||
Reference in New Issue
Block a user