diff --git a/cmd/publish_switch.go b/cmd/publish_switch.go index f41403f4..c8cb6f8e 100644 --- a/cmd/publish_switch.go +++ b/cmd/publish_switch.go @@ -3,6 +3,7 @@ package cmd import ( "fmt" "github.com/smira/aptly/deb" + "github.com/smira/aptly/utils" "github.com/smira/commander" "github.com/smira/flag" "strings" @@ -61,6 +62,10 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error { } for i, component := range components { + if !utils.StrSliceHasItem(publishedComponents, component) { + return fmt.Errorf("unable to switch: component %s is not in published repository", component) + } + snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(names[i]) if err != nil { return fmt.Errorf("unable to switch: %s", err) diff --git a/system/t06_publish/PublishSwitch12Test_gold b/system/t06_publish/PublishSwitch12Test_gold new file mode 100644 index 00000000..2fb3bcac --- /dev/null +++ b/system/t06_publish/PublishSwitch12Test_gold @@ -0,0 +1 @@ +ERROR: unable to switch: component c is not in published repository diff --git a/system/t06_publish/switch.py b/system/t06_publish/switch.py index 0abd8dd5..51bfc82f 100644 --- a/system/t06_publish/switch.py +++ b/system/t06_publish/switch.py @@ -388,3 +388,15 @@ class PublishSwitch11Test(BaseTest): self.check_file_contents("public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz", "file") + +class PublishSwitch12Test(BaseTest): + """ + publish switch: wrong component names + """ + fixtureCmds = [ + "aptly snapshot create snap1 empty", + "aptly snapshot create snap2 empty", + "aptly publish snapshot -architectures=i386 -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -distribution=maverick -component=a,b snap1 snap2", + ] + runCmd = "aptly publish switch -keyring=${files}/aptly.pub -secret-keyring=${files}/aptly.sec -component=a,c maverick snap2 snap1" + expectedCode = 1