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
769b7d20
Commit
769b7d20
authored
Jun 08, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
amazon/ebs: acceptance test for region copy
parent
3427dc9e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
0 deletions
+70
-0
builder/amazon/ebs/builder_acc_test.go
builder/amazon/ebs/builder_acc_test.go
+70
-0
No files found.
builder/amazon/ebs/builder_acc_test.go
View file @
769b7d20
package
ebs
import
(
"fmt"
"os"
"testing"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/mitchellh/packer/builder/amazon/common"
builderT
"github.com/mitchellh/packer/helper/builder/testing"
"github.com/mitchellh/packer/packer"
)
func
TestBuilderAcc_basic
(
t
*
testing
.
T
)
{
...
...
@@ -15,6 +19,48 @@ func TestBuilderAcc_basic(t *testing.T) {
})
}
func
TestBuilderAcc_regionCopy
(
t
*
testing
.
T
)
{
builderT
.
Test
(
t
,
builderT
.
TestCase
{
PreCheck
:
func
()
{
testAccPreCheck
(
t
)
},
Builder
:
&
Builder
{},
Template
:
testBuilderAccRegionCopy
,
Check
:
checkRegionCopy
([]
string
{
"us-east-1"
,
"us-west-2"
}),
})
}
func
checkRegionCopy
(
regions
[]
string
)
builderT
.
TestCheckFunc
{
return
func
(
artifacts
[]
packer
.
Artifact
)
error
{
if
len
(
artifacts
)
>
1
{
return
fmt
.
Errorf
(
"more than 1 artifact"
)
}
// Get the actual *Artifact pointer so we can access the AMIs directly
artifactRaw
:=
artifacts
[
0
]
artifact
,
ok
:=
artifactRaw
.
(
*
common
.
Artifact
)
if
!
ok
{
return
fmt
.
Errorf
(
"unknown artifact: %#v"
,
artifactRaw
)
}
// Verify that we copied to only the regions given
regionSet
:=
make
(
map
[
string
]
struct
{})
for
_
,
r
:=
range
regions
{
regionSet
[
r
]
=
struct
{}{}
}
for
r
,
_
:=
range
artifact
.
Amis
{
if
_
,
ok
:=
regionSet
[
r
];
!
ok
{
return
fmt
.
Errorf
(
"unknown region: %s"
,
r
)
}
delete
(
regionSet
,
r
)
}
if
len
(
regionSet
)
>
0
{
return
fmt
.
Errorf
(
"didn't copy to: %#v"
,
regionSet
)
}
return
nil
}
}
func
testAccPreCheck
(
t
*
testing
.
T
)
{
if
v
:=
os
.
Getenv
(
"AWS_ACCESS_KEY_ID"
);
v
==
""
{
t
.
Fatal
(
"AWS_ACCESS_KEY_ID must be set for acceptance tests"
)
...
...
@@ -25,6 +71,16 @@ func testAccPreCheck(t *testing.T) {
}
}
func
testEC2Conn
()
(
*
ec2
.
EC2
,
error
)
{
access
:=
&
common
.
AccessConfig
{
RawRegion
:
"us-east-1"
}
config
,
err
:=
access
.
Config
()
if
err
!=
nil
{
return
nil
,
err
}
return
ec2
.
New
(
config
),
nil
}
const
testBuilderAccBasic
=
`
{
"builders": [{
...
...
@@ -37,3 +93,17 @@ const testBuilderAccBasic = `
}]
}
`
const
testBuilderAccRegionCopy
=
`
{
"builders": [{
"type": "test",
"region": "us-east-1",
"instance_type": "m3.medium",
"source_ami": "ami-76b2a71e",
"ssh_username": "ubuntu",
"ami_name": "packer-test {{timestamp}}",
"ami_regions": ["us-east-1", "us-west-2"]
}]
}
`
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