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
86206e31
Commit
86206e31
authored
Jun 12, 2015
by
Clint Shryock
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tags test
parent
1fbf8b7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
0 deletions
+114
-0
builder/amazon/ebs/tags_acc_test.go
builder/amazon/ebs/tags_acc_test.go
+114
-0
No files found.
builder/amazon/ebs/tags_acc_test.go
0 → 100644
View file @
86206e31
package
ebs
import
(
"fmt"
"testing"
"github.com/aws/aws-sdk-go/aws"
"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
TestBuilderTagsAcc_basic
(
t
*
testing
.
T
)
{
builderT
.
Test
(
t
,
builderT
.
TestCase
{
PreCheck
:
func
()
{
testAccPreCheck
(
t
)
},
Builder
:
&
Builder
{},
Template
:
testBuilderTagsAccBasic
,
Check
:
checkTags
(),
})
}
func
checkTags
()
builderT
.
TestCheckFunc
{
return
func
(
artifacts
[]
packer
.
Artifact
)
error
{
if
len
(
artifacts
)
>
1
{
return
fmt
.
Errorf
(
"more than 1 artifact"
)
}
tags
:=
make
(
map
[
string
]
string
)
tags
[
"OS_Version"
]
=
"Ubuntu"
tags
[
"Release"
]
=
"Latest"
// 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
)
}
// describe the image, get block devices with a snapshot
ec2conn
,
_
:=
testEC2Conn
()
imageResp
,
err
:=
ec2conn
.
DescribeImages
(
&
ec2
.
DescribeImagesInput
{
ImageIDs
:
[]
*
string
{
aws
.
String
(
artifact
.
Amis
[
"us-east-1"
])},
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error retrieving details for AMI Artifcat (%#v) in Tags Test: %s"
,
artifact
,
err
)
}
if
len
(
imageResp
.
Images
)
==
0
{
return
fmt
.
Errorf
(
"No images found for AMI Artifcat (%#v) in Tags Test: %s"
,
artifact
,
err
)
}
image
:=
imageResp
.
Images
[
0
]
// Check only those with a Snapshot ID, i.e. not Ephemeral
var
snapshots
[]
*
string
for
_
,
device
:=
range
image
.
BlockDeviceMappings
{
if
device
.
EBS
!=
nil
&&
device
.
EBS
.
SnapshotID
!=
nil
{
snapshots
=
append
(
snapshots
,
device
.
EBS
.
SnapshotID
)
}
}
// grab matching snapshot info
resp
,
err
:=
ec2conn
.
DescribeSnapshots
(
&
ec2
.
DescribeSnapshotsInput
{
SnapshotIDs
:
snapshots
,
})
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Error retreiving Snapshots for AMI Artifcat (%#v) in Tags Test: %s"
,
artifact
,
err
)
}
if
len
(
resp
.
Snapshots
)
==
0
{
return
fmt
.
Errorf
(
"No Snapshots found for AMI Artifcat (%#v) in Tags Test"
,
artifact
)
}
// grab the snapshots, check the tags
for
_
,
s
:=
range
resp
.
Snapshots
{
expected
:=
len
(
tags
)
for
_
,
t
:=
range
s
.
Tags
{
for
key
,
value
:=
range
tags
{
if
key
==
*
t
.
Key
&&
value
==
*
t
.
Value
{
expected
--
}
}
}
if
expected
>
0
{
return
fmt
.
Errorf
(
"Not all tags found"
)
}
}
return
nil
}
}
const
testBuilderTagsAccBasic
=
`
{
"builders": [
{
"type": "test",
"region": "us-east-1",
"source_ami": "ami-9eaa1cf6",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-tags-testing-{{timestamp}}",
"tags": {
"OS_Version": "Ubuntu",
"Release": "Latest"
}
}
]
}
`
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