common/command: error if only/except points to bad build
This commit is contained in:
parent
9cc4137a19
commit
4c86547796
|
@ -1,6 +1,9 @@
|
|||
## 0.3.5 (unreleased)
|
||||
|
||||
BUG FIXES:
|
||||
|
||||
* command/build,command/validate: If a non-existent build is specified to
|
||||
'-only' or '-except', it is now an error. [GH-326]
|
||||
|
||||
## 0.3.4 (August 21, 2013)
|
||||
|
||||
|
|
|
@ -65,6 +65,27 @@ func (f *BuildOptions) AllUserVars() (map[string]string, error) {
|
|||
// configured options.
|
||||
func (f *BuildOptions) Builds(t *packer.Template, cf *packer.ComponentFinder) ([]packer.Build, error) {
|
||||
buildNames := t.BuildNames()
|
||||
|
||||
checks := make(map[string][]string)
|
||||
checks["except"] = f.Except
|
||||
checks["only"] = f.Only
|
||||
for t, ns := range checks {
|
||||
for _, n := range ns {
|
||||
found := false
|
||||
for _, actual := range buildNames {
|
||||
if actual == n {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, fmt.Errorf(
|
||||
"Unknown build in '%s' flag: %s", t, n)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
builds := make([]packer.Build, 0, len(buildNames))
|
||||
for _, buildName := range buildNames {
|
||||
if len(f.Except) > 0 {
|
||||
|
|
|
@ -77,6 +77,26 @@ func TestBuildOptionsBuilds_only(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBuildOptionsBuilds_exceptNonExistent(t *testing.T) {
|
||||
opts := new(BuildOptions)
|
||||
opts.Except = []string{"i-dont-exist"}
|
||||
|
||||
_, err := opts.Builds(testTemplate())
|
||||
if err == nil {
|
||||
t.Fatal("err should not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildOptionsBuilds_onlyNonExistent(t *testing.T) {
|
||||
opts := new(BuildOptions)
|
||||
opts.Only = []string{"i-dont-exist"}
|
||||
|
||||
_, err := opts.Builds(testTemplate())
|
||||
if err == nil {
|
||||
t.Fatal("err should not be nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildOptionsValidate(t *testing.T) {
|
||||
bf := new(BuildOptions)
|
||||
|
||||
|
|
Loading…
Reference in New Issue