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
472b0603
Commit
472b0603
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: build_name and build_type work + tests
parent
f1b3c8a7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
0 deletions
+74
-0
helper/config/decode.go
helper/config/decode.go
+4
-0
packer/core_test.go
packer/core_test.go
+58
-0
packer/test-fixtures/build-var-build-name.json
packer/test-fixtures/build-var-build-name.json
+6
-0
packer/test-fixtures/build-var-build-type.json
packer/test-fixtures/build-var-build-type.json
+6
-0
No files found.
helper/config/decode.go
View file @
472b0603
...
...
@@ -104,6 +104,8 @@ func Decode(target interface{}, config *DecodeOpts, raws ...interface{}) error {
// detecting things like user variables from the raw configuration params.
func
DetectContext
(
raws
...
interface
{})
(
*
interpolate
.
Context
,
error
)
{
var
s
struct
{
BuildName
string
`mapstructure:"packer_build_name"`
BuildType
string
`mapstructure:"packer_builder_type"`
TemplatePath
string
`mapstructure:"packer_template_path"`
Vars
map
[
string
]
string
`mapstructure:"packer_user_variables"`
}
...
...
@@ -115,6 +117,8 @@ func DetectContext(raws ...interface{}) (*interpolate.Context, error) {
}
return
&
interpolate
.
Context
{
BuildName
:
s
.
BuildName
,
BuildType
:
s
.
BuildType
,
TemplatePath
:
s
.
TemplatePath
,
UserVariables
:
s
.
Vars
,
},
nil
...
...
packer/core_test.go
View file @
472b0603
...
...
@@ -142,6 +142,64 @@ func TestCoreBuild_env(t *testing.T) {
}
}
func
TestCoreBuild_buildNameVar
(
t
*
testing
.
T
)
{
config
:=
TestCoreConfig
(
t
)
testCoreTemplate
(
t
,
config
,
fixtureDir
(
"build-var-build-name.json"
))
b
:=
TestBuilder
(
t
,
config
,
"test"
)
core
:=
TestCore
(
t
,
config
)
b
.
ArtifactId
=
"hello"
build
,
err
:=
core
.
Build
(
"test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
_
,
err
:=
build
.
Prepare
();
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Interpolate the config
var
result
map
[
string
]
interface
{}
err
=
configHelper
.
Decode
(
&
result
,
nil
,
b
.
PrepareConfig
...
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
result
[
"value"
]
!=
"test"
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
}
func
TestCoreBuild_buildTypeVar
(
t
*
testing
.
T
)
{
config
:=
TestCoreConfig
(
t
)
testCoreTemplate
(
t
,
config
,
fixtureDir
(
"build-var-build-type.json"
))
b
:=
TestBuilder
(
t
,
config
,
"test"
)
core
:=
TestCore
(
t
,
config
)
b
.
ArtifactId
=
"hello"
build
,
err
:=
core
.
Build
(
"test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
_
,
err
:=
build
.
Prepare
();
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
// Interpolate the config
var
result
map
[
string
]
interface
{}
err
=
configHelper
.
Decode
(
&
result
,
nil
,
b
.
PrepareConfig
...
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
result
[
"value"
]
!=
"test"
{
t
.
Fatalf
(
"bad: %#v"
,
result
)
}
}
func
TestCoreBuild_nonExist
(
t
*
testing
.
T
)
{
config
:=
TestCoreConfig
(
t
)
testCoreTemplate
(
t
,
config
,
fixtureDir
(
"build-basic.json"
))
...
...
packer/test-fixtures/build-var-build-name.json
0 → 100644
View file @
472b0603
{
"builders"
:
[{
"type"
:
"test"
,
"value"
:
"{{build_name}}"
}]
}
packer/test-fixtures/build-var-build-type.json
0 → 100644
View file @
472b0603
{
"builders"
:
[{
"type"
:
"test"
,
"value"
:
"{{build_type}}"
}]
}
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