Check component names (that they do exist) before publish switching. #192

This commit is contained in:
Andrey Smirnov
2015-02-06 20:16:00 +03:00
parent 5d16cf06cf
commit 06502584cf
3 changed files with 18 additions and 0 deletions
+5
View File
@@ -3,6 +3,7 @@ package cmd
import ( import (
"fmt" "fmt"
"github.com/smira/aptly/deb" "github.com/smira/aptly/deb"
"github.com/smira/aptly/utils"
"github.com/smira/commander" "github.com/smira/commander"
"github.com/smira/flag" "github.com/smira/flag"
"strings" "strings"
@@ -61,6 +62,10 @@ func aptlyPublishSwitch(cmd *commander.Command, args []string) error {
} }
for i, component := range components { 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]) snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(names[i])
if err != nil { if err != nil {
return fmt.Errorf("unable to switch: %s", err) return fmt.Errorf("unable to switch: %s", err)
@@ -0,0 +1 @@
ERROR: unable to switch: component c is not in published repository
+12
View File
@@ -388,3 +388,15 @@ class PublishSwitch11Test(BaseTest):
self.check_file_contents("public/pool/main/p/pyspi/pyspi_0.6.1.orig.tar.gz", "file") 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