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
ab2af979
Commit
ab2af979
authored
Jul 14, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
command/fix: fixer for iso_md5 change
parent
aae210f1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
0 deletions
+107
-0
command/fix/fixer.go
command/fix/fixer.go
+18
-0
command/fix/fixer_iso_md5.go
command/fix/fixer_iso_md5.go
+43
-0
command/fix/fixer_iso_md5_test.go
command/fix/fixer_iso_md5_test.go
+46
-0
No files found.
command/fix/fixer.go
0 → 100644
View file @
ab2af979
package
fix
// A Fixer is something that can perform a fix operation on a template.
type
Fixer
interface
{
// Fix takes a raw map structure input, potentially transforms it
// in some way, and returns the new, transformed structure. The
// Fix method is allowed to mutate the input.
Fix
(
input
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
}
// Fixers is the map of all available fixers, by name.
var
Fixers
map
[
string
]
Fixer
func
init
()
{
Fixers
=
map
[
string
]
Fixer
{
"iso-md5"
:
new
(
FixerISOMD5
),
}
}
command/fix/fixer_iso_md5.go
0 → 100644
View file @
ab2af979
package
fix
import
(
"github.com/mitchellh/mapstructure"
)
// FixerISOMD5 is a Fixer that replaces the "iso_md5" configuration key
// with the newer "iso_checksum" and "iso_checksum_type" within builders.
type
FixerISOMD5
struct
{}
func
(
FixerISOMD5
)
Fix
(
input
map
[
string
]
interface
{})
(
map
[
string
]
interface
{},
error
)
{
// Our template type we'll use for this fixer only
type
template
struct
{
Builders
[]
map
[
string
]
interface
{}
}
// Decode the input into our structure, if we can
var
tpl
template
if
err
:=
mapstructure
.
Decode
(
input
,
&
tpl
);
err
!=
nil
{
return
nil
,
err
}
// Go through each builder and replace the iso_md5 if we can
for
_
,
builder
:=
range
tpl
.
Builders
{
md5raw
,
ok
:=
builder
[
"iso_md5"
]
if
!
ok
{
continue
}
md5
,
ok
:=
md5raw
.
(
string
)
if
!
ok
{
// TODO: error?
continue
}
delete
(
builder
,
"iso_md5"
)
builder
[
"iso_checksum"
]
=
md5
builder
[
"iso_checksum_type"
]
=
"md5"
}
input
[
"builders"
]
=
tpl
.
Builders
return
input
,
nil
}
command/fix/fixer_iso_md5_test.go
0 → 100644
View file @
ab2af979
package
fix
import
(
"reflect"
"testing"
)
func
TestFixerISOMD5_Impl
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
new
(
FixerISOMD5
)
if
_
,
ok
:=
raw
.
(
Fixer
);
!
ok
{
t
.
Fatalf
(
"must be a Fixer"
)
}
}
func
TestFixerISOMD5_Fix
(
t
*
testing
.
T
)
{
var
f
FixerISOMD5
input
:=
map
[
string
]
interface
{}{
"builders"
:
[]
interface
{}{
map
[
string
]
string
{
"type"
:
"foo"
,
"iso_md5"
:
"bar"
,
},
},
}
expected
:=
map
[
string
]
interface
{}{
"builders"
:
[]
map
[
string
]
interface
{}{
map
[
string
]
interface
{}{
"type"
:
"foo"
,
"iso_checksum"
:
"bar"
,
"iso_checksum_type"
:
"md5"
,
},
},
}
output
,
err
:=
f
.
Fix
(
input
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
!
reflect
.
DeepEqual
(
output
,
expected
)
{
t
.
Fatalf
(
"unexpected: %#v
\n
expected: %#v
\n
"
,
output
,
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