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
a4f674f8
Commit
a4f674f8
authored
Aug 22, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/common: remove duplicates from ami_region
/cc @jmassara
parent
c91ff5f2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
1 deletion
+42
-1
builder/amazon/common/ami_config.go
builder/amazon/common/ami_config.go
+17
-0
builder/amazon/common/ami_config_test.go
builder/amazon/common/ami_config_test.go
+25
-1
No files found.
builder/amazon/common/ami_config.go
View file @
a4f674f8
...
@@ -63,11 +63,28 @@ func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
...
@@ -63,11 +63,28 @@ func (c *AMIConfig) Prepare(t *packer.ConfigTemplate) []error {
}
}
if
len
(
c
.
AMIRegions
)
>
0
{
if
len
(
c
.
AMIRegions
)
>
0
{
regionSet
:=
make
(
map
[
string
]
struct
{})
regions
:=
make
([]
string
,
0
,
len
(
c
.
AMIRegions
))
for
_
,
region
:=
range
c
.
AMIRegions
{
for
_
,
region
:=
range
c
.
AMIRegions
{
// If we already saw the region, then don't look again
if
_
,
ok
:=
regionSet
[
region
];
ok
{
continue
}
// Mark that we saw the region
regionSet
[
region
]
=
struct
{}{}
// Verify the region is real
if
_
,
ok
:=
aws
.
Regions
[
region
];
!
ok
{
if
_
,
ok
:=
aws
.
Regions
[
region
];
!
ok
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unknown region: %s"
,
region
))
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Unknown region: %s"
,
region
))
continue
}
}
regions
=
append
(
regions
,
region
)
}
}
c
.
AMIRegions
=
regions
}
}
if
len
(
errs
)
>
0
{
if
len
(
errs
)
>
0
{
...
...
builder/amazon/common/ami_config_test.go
View file @
a4f674f8
package
common
package
common
import
(
import
(
"reflect"
"testing"
"testing"
)
)
...
@@ -10,7 +11,7 @@ func testAMIConfig() *AMIConfig {
...
@@ -10,7 +11,7 @@ func testAMIConfig() *AMIConfig {
}
}
}
}
func
TestAMIConfigPrepare_
Region
(
t
*
testing
.
T
)
{
func
TestAMIConfigPrepare_
name
(
t
*
testing
.
T
)
{
c
:=
testAMIConfig
()
c
:=
testAMIConfig
()
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
...
@@ -21,3 +22,26 @@ func TestAMIConfigPrepare_Region(t *testing.T) {
...
@@ -21,3 +22,26 @@ func TestAMIConfigPrepare_Region(t *testing.T) {
t
.
Fatal
(
"should have error"
)
t
.
Fatal
(
"should have error"
)
}
}
}
}
func
TestAMIConfigPrepare_regions
(
t
*
testing
.
T
)
{
c
:=
testAMIConfig
()
c
.
AMIRegions
=
nil
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
}
c
.
AMIRegions
=
[]
string
{
"foo"
}
if
err
:=
c
.
Prepare
(
nil
);
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
c
.
AMIRegions
=
[]
string
{
"us-east-1"
,
"us-west-1"
,
"us-east-1"
}
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
expected
:=
[]
string
{
"us-east-1"
,
"us-west-1"
}
if
!
reflect
.
DeepEqual
(
c
.
AMIRegions
,
expected
)
{
t
.
Fatalf
(
"bad: %#v"
,
c
.
AMIRegions
)
}
}
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