Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
ac2a4807
Commit
ac2a4807
authored
Aug 31, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: fix required var check to work properly
parent
fd4b01cf
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
15 deletions
+16
-15
packer/build.go
packer/build.go
+8
-15
packer/build_test.go
packer/build_test.go
+8
-0
No files found.
packer/build.go
View file @
ac2a4807
...
...
@@ -126,14 +126,19 @@ func (b *coreBuild) Prepare(userVars map[string]string) (err error) {
b
.
prepareCalled
=
true
// Compile the variables
varErrs
:=
make
([]
error
,
0
)
variables
:=
make
(
map
[
string
]
string
)
for
k
,
v
:=
range
b
.
variables
{
if
!
v
.
Required
{
variables
[
k
]
=
v
.
Default
if
v
.
Required
{
if
_
,
ok
:=
userVars
[
k
];
!
ok
{
varErrs
=
append
(
varErrs
,
fmt
.
Errorf
(
"Required user variable '%s' not set"
,
k
))
}
}
}
varErrs
:=
make
([]
error
,
0
)
if
userVars
!=
nil
{
for
k
,
v
:=
range
userVars
{
if
_
,
ok
:=
variables
[
k
];
!
ok
{
...
...
@@ -146,18 +151,6 @@ func (b *coreBuild) Prepare(userVars map[string]string) (err error) {
}
}
// Verify all required variables have been set.
for
k
,
v
:=
range
b
.
variables
{
if
!
v
.
Required
{
continue
}
if
_
,
ok
:=
variables
[
k
];
!
ok
{
varErrs
=
append
(
varErrs
,
fmt
.
Errorf
(
"Required user variable '%s' not set"
,
k
))
}
}
// If there were any problem with variables, return an error right
// away because we can't be certain anything else will actually work.
if
len
(
varErrs
)
>
0
{
...
...
packer/build_test.go
View file @
ac2a4807
...
...
@@ -175,6 +175,14 @@ func TestBuildPrepare_variablesRequired(t *testing.T) {
if
err
==
nil
{
t
.
Fatal
(
"should have had error"
)
}
// Test with setting the value
build
=
testBuild
()
build
.
variables
[
"foo"
]
=
coreBuildVariable
{
Required
:
true
}
err
=
build
.
Prepare
(
map
[
string
]
string
{
"foo"
:
""
})
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuild_Run
(
t
*
testing
.
T
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment