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
c3f54ba5
Commit
c3f54ba5
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: virtualbox rename fixes overrides [GH-1828]
parent
7eff6b11
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
4 deletions
+78
-4
fix/fixer_virtualbox_rename.go
fix/fixer_virtualbox_rename.go
+36
-4
fix/fixer_virtualbox_rename_test.go
fix/fixer_virtualbox_rename_test.go
+42
-0
No files found.
fix/fixer_virtualbox_rename.go
View file @
c3f54ba5
...
...
@@ -8,14 +8,14 @@ import (
type
FixerVirtualBoxRename
struct
{}
func
(
FixerVirtualBoxRename
)
Fix
(
input
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
// The type we'll decode into; we only care about builders
type
template
struct
{
Builders
[]
map
[
string
]
interface
{}
Builders
[]
map
[
string
]
interface
{}
Provisioners
[]
interface
{}
}
// Decode the input into our structure, if we can
var
tpl
template
if
err
:=
mapstructure
.
Decode
(
input
,
&
tpl
);
err
!=
nil
{
if
err
:=
mapstructure
.
Weak
Decode
(
input
,
&
tpl
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -37,7 +37,39 @@ func (FixerVirtualBoxRename) Fix(input map[string]interface{}) (map[string]inter
builder
[
"type"
]
=
"virtualbox-iso"
}
input
[
"builders"
]
=
tpl
.
Builders
for
i
,
raw
:=
range
tpl
.
Provisioners
{
var
m
map
[
string
]
interface
{}
if
err
:=
mapstructure
.
WeakDecode
(
raw
,
&
m
);
err
!=
nil
{
// Ignore errors, could be a non-map
continue
}
raw
,
ok
:=
m
[
"override"
]
if
!
ok
{
continue
}
var
override
map
[
string
]
interface
{}
if
err
:=
mapstructure
.
WeakDecode
(
raw
,
&
override
);
err
!=
nil
{
return
nil
,
err
}
if
raw
,
ok
:=
override
[
"virtualbox"
];
ok
{
override
[
"virtualbox-iso"
]
=
raw
delete
(
override
,
"virtualbox"
)
// Set the change
m
[
"override"
]
=
override
tpl
.
Provisioners
[
i
]
=
m
}
}
if
len
(
tpl
.
Builders
)
>
0
{
input
[
"builders"
]
=
tpl
.
Builders
}
if
len
(
tpl
.
Provisioners
)
>
0
{
input
[
"provisioners"
]
=
tpl
.
Provisioners
}
return
input
,
nil
}
...
...
fix/fixer_virtualbox_rename_test.go
View file @
c3f54ba5
...
...
@@ -46,3 +46,45 @@ func TestFixerVirtualBoxRename_Fix(t *testing.T) {
}
}
}
func
TestFixerVirtualBoxRenameFix_provisionerOverride
(
t
*
testing
.
T
)
{
cases
:=
[]
struct
{
Input
map
[
string
]
interface
{}
Expected
map
[
string
]
interface
{}
}{
{
Input
:
map
[
string
]
interface
{}{
"provisioners"
:
[]
interface
{}{
map
[
string
]
interface
{}{
"override"
:
map
[
string
]
interface
{}{
"virtualbox"
:
map
[
string
]
interface
{}{},
},
},
},
},
Expected
:
map
[
string
]
interface
{}{
"provisioners"
:
[]
interface
{}{
map
[
string
]
interface
{}{
"override"
:
map
[
string
]
interface
{}{
"virtualbox-iso"
:
map
[
string
]
interface
{}{},
},
},
},
},
},
}
for
_
,
tc
:=
range
cases
{
var
f
FixerVirtualBoxRename
output
,
err
:=
f
.
Fix
(
tc
.
Input
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
output
,
tc
.
Expected
)
{
t
.
Fatalf
(
"unexpected:
\n\n
%#v
\n
expected:
\n\n
%#v
\n
"
,
output
,
tc
.
Expected
)
}
}
}
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