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
a61f1786
Commit
a61f1786
authored
Jul 19, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/common: CheckUnusedConfig
parent
42059f9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
builder/common/config.go
builder/common/config.go
+26
-0
builder/common/config_test.go
builder/common/config_test.go
+18
-0
No files found.
builder/common/config.go
View file @
a61f1786
package
common
import
(
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"sort"
"strings"
)
// CheckUnusedConfig is a helper that makes sure that the there are no
// unused configuration keys, properly ignoring keys that don't matter.
func
CheckUnusedConfig
(
md
*
mapstructure
.
Metadata
)
error
{
errs
:=
make
([]
error
,
0
)
if
md
.
Unused
!=
nil
&&
len
(
md
.
Unused
)
>
0
{
sort
.
Strings
(
md
.
Unused
)
for
_
,
unused
:=
range
md
.
Unused
{
if
unused
!=
"type"
&&
!
strings
.
HasPrefix
(
unused
,
"packer_"
)
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unknown configuration key: %s"
,
unused
))
}
}
}
if
len
(
errs
)
>
0
{
return
&
packer
.
MultiError
{
errs
}
}
return
nil
}
// DecodeConfig is a helper that handles decoding raw configuration using
// mapstructure. It returns the metadata and any errors that may happen.
// If you need extra configuration for mapstructure, you should configure
...
...
builder/common/config_test.go
View file @
a61f1786
package
common
import
(
"github.com/mitchellh/mapstructure"
"reflect"
"testing"
)
func
TestCheckUnusedConfig
(
t
*
testing
.
T
)
{
md
:=
&
mapstructure
.
Metadata
{
Unused
:
make
([]
string
,
0
),
}
err
:=
CheckUnusedConfig
(
md
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
md
.
Unused
=
[]
string
{
"foo"
,
"bar"
}
err
=
CheckUnusedConfig
(
md
)
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestDecodeConfig
(
t
*
testing
.
T
)
{
type
Local
struct
{
Foo
string
...
...
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