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
ba05119a
Commit
ba05119a
authored
Apr 28, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: user variable conversion to non-string types works [GH-1079]
parent
d236e139
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
common/config.go
common/config.go
+9
-0
common/config_test.go
common/config_test.go
+26
-0
No files found.
common/config.go
View file @
ba05119a
...
...
@@ -217,6 +217,15 @@ func decodeConfigHook(raws []interface{}) (mapstructure.DecodeHookFunc, error) {
return
func
(
f
reflect
.
Kind
,
t
reflect
.
Kind
,
v
interface
{})
(
interface
{},
error
)
{
if
t
!=
reflect
.
String
{
if
f
==
reflect
.
Slice
{
dataVal
:=
reflect
.
ValueOf
(
v
)
dataType
:=
dataVal
.
Type
()
elemKind
:=
dataType
.
Elem
()
.
Kind
()
if
elemKind
==
reflect
.
Uint8
{
v
=
string
(
dataVal
.
Interface
()
.
([]
uint8
))
}
}
if
sv
,
ok
:=
v
.
(
string
);
ok
{
var
err
error
v
,
err
=
tpl
.
Process
(
sv
,
nil
)
...
...
common/config_test.go
View file @
ba05119a
...
...
@@ -148,6 +148,32 @@ func TestDecodeConfig_userVarConversion(t *testing.T) {
}
}
// This tests the way MessagePack decodes strings (into []uint8) and
// that we can still decode into the proper types.
func
TestDecodeConfig_userVarConversionUInt8
(
t
*
testing
.
T
)
{
type
Local
struct
{
Val
int
}
raw
:=
map
[
string
]
interface
{}{
"packer_user_variables"
:
map
[
string
]
string
{
"foo"
:
"42"
,
},
"val"
:
[]
uint8
(
"{{user `foo`}}"
),
}
var
result
Local
_
,
err
:=
DecodeConfig
(
&
result
,
raw
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
result
.
Val
!=
42
{
t
.
Fatalf
(
"invalid: %#v"
,
result
.
Val
)
}
}
func
TestDownloadableURL
(
t
*
testing
.
T
)
{
// Invalid URL: has hex code in host
_
,
err
:=
DownloadableURL
(
"http://what%20.com"
)
...
...
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