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
6d0fa84e
Commit
6d0fa84e
authored
May 09, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazonebs: Read config
parent
9600bf5b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
5 deletions
+61
-5
builder/amazonebs/builder.go
builder/amazonebs/builder.go
+23
-5
builder/amazonebs/builder_test.go
builder/amazonebs/builder_test.go
+38
-0
No files found.
builder/amazonebs/builder.go
View file @
6d0fa84e
package
amazonebs
package
amazonebs
import
(
import
(
"encoding/json"
"errors"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
)
)
type
config
struct
{
type
config
struct
{
AccessKey
string
AccessKey
string
`json:"access_key"`
Region
string
Region
string
SecretKey
string
SecretKey
string
`json:"secret_key"`
SourceAmi
string
SourceAmi
string
`json:"source_ami"`
}
}
type
Builder
struct
{
type
Builder
struct
{
config
config
config
config
}
}
func
(
*
Builder
)
Prepare
(
interface
{})
error
{
func
(
b
*
Builder
)
Prepare
(
raw
interface
{})
(
err
error
)
{
return
nil
_
,
ok
:=
raw
.
(
map
[
string
]
interface
{})
if
!
ok
{
err
=
errors
.
New
(
"configuration isn't a valid map"
)
return
}
jsonBytes
,
err
:=
json
.
Marshal
(
raw
)
if
err
!=
nil
{
return
}
err
=
json
.
Unmarshal
(
jsonBytes
,
&
b
.
config
)
if
err
!=
nil
{
return
}
return
}
}
func
(
*
Builder
)
Run
(
packer
.
Build
,
packer
.
Ui
)
{}
func
(
*
Builder
)
Run
(
packer
.
Build
,
packer
.
Ui
)
{}
builder/amazonebs/builder_test.go
View file @
6d0fa84e
...
@@ -12,3 +12,41 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
...
@@ -12,3 +12,41 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
var
actual
packer
.
Builder
var
actual
packer
.
Builder
assert
.
Implementor
(
&
Builder
{},
&
actual
,
"should be a Builder"
)
assert
.
Implementor
(
&
Builder
{},
&
actual
,
"should be a Builder"
)
}
}
func
TestBuilder_Prepare_NotMap
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
b
:=
&
Builder
{}
err
:=
b
.
Prepare
(
42
)
assert
.
NotNil
(
err
,
"should have an error"
)
assert
.
Equal
(
err
.
Error
(),
"configuration isn't a valid map"
,
"config is not a map"
)
}
func
TestBuilder_Prepare_BadType
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
b
:=
&
Builder
{}
c
:=
map
[
string
]
interface
{}
{
"access_key"
:
[]
string
{},
}
err
:=
b
.
Prepare
(
c
)
assert
.
NotNil
(
err
,
"should have an error"
)
}
func
TestBuilder_Prepare_Good
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
b
:=
&
Builder
{}
c
:=
map
[
string
]
interface
{}
{
"access_key"
:
"foo"
,
"secret_key"
:
"bar"
,
"source_ami"
:
"123456"
,
}
err
:=
b
.
Prepare
(
c
)
assert
.
Nil
(
err
,
"should not have an error"
)
assert
.
Equal
(
b
.
config
.
AccessKey
,
"foo"
,
"should be valid access key"
)
assert
.
Equal
(
b
.
config
.
SecretKey
,
"bar"
,
"should be valid secret key"
)
assert
.
Equal
(
b
.
config
.
SourceAmi
,
"123456"
,
"should have source AMI"
)
}
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