本文整理匯總了Golang中github.com/endemics/docker-plugin-ebs/ec2/mocks.EC2類的典型用法代碼示例。如果您正苦於以下問題:Golang EC2類的具體用法?Golang EC2怎麽用?Golang EC2使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了EC2類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCreateReturnsErrorWhenSizeOrIopsAreInvalid
func TestCreateReturnsErrorWhenSizeOrIopsAreInvalid(t *testing.T) {
optsTests := []map[string]string{
{
"size": "x",
},
{
"iops": "y",
},
}
mockOutput := &ec2.Volume{
AvailabilityZone: aws.String("eu-west-1a"),
CreateTime: aws.Time(time.Now()),
Encrypted: aws.Bool(false),
Iops: aws.Int64(3),
Size: aws.Int64(1),
SnapshotId: aws.String(""),
State: aws.String("creating"),
VolumeId: aws.String("vol-681e4aac"),
VolumeType: aws.String("gp2"),
}
m := new(mocks.EC2)
m.On("CreateVolume", mock.AnythingOfType("*ec2.CreateVolumeInput")).Return(mockOutput, nil)
wrapper := &EC2Wrapper{m}
for _, tt := range optsTests {
_, err := wrapper.create("label", tt)
assert.Error(t, err, "create should return an error when size or iops cannot be converted in int64")
}
}
示例2: TestFindReturnsErrorIfMoreThanOneVolumeMatchesLabel
func TestFindReturnsErrorIfMoreThanOneVolumeMatchesLabel(t *testing.T) {
mockOutput := &ec2.DescribeVolumesOutput{
Volumes: []*ec2.Volume{
&ec2.Volume{
AvailabilityZone: aws.String("eu-west-1a"),
CreateTime: aws.Time(time.Now()),
Encrypted: aws.Bool(false),
Iops: aws.Int64(3),
Size: aws.Int64(1),
SnapshotId: aws.String(""),
State: aws.String("available"),
Tags: []*ec2.Tag{
&ec2.Tag{
Key: aws.String("Name"),
Value: aws.String("label"),
},
&ec2.Tag{
Key: aws.String("DockerVolumeName"),
Value: aws.String("label"),
},
},
VolumeId: aws.String("vol-681e4aac"),
VolumeType: aws.String("gp2"),
},
&ec2.Volume{
AvailabilityZone: aws.String("eu-west-1b"),
CreateTime: aws.Time(time.Now()),
Encrypted: aws.Bool(false),
Iops: aws.Int64(3),
Size: aws.Int64(1),
SnapshotId: aws.String(""),
State: aws.String("available"),
Tags: []*ec2.Tag{
&ec2.Tag{
Key: aws.String("Name"),
Value: aws.String("label"),
},
&ec2.Tag{
Key: aws.String("DockerVolumeName"),
Value: aws.String("label"),
},
},
VolumeId: aws.String("vol-1234beef"),
VolumeType: aws.String("gp2"),
},
},
}
m := new(mocks.EC2)
m.On("DescribeVolumes", mock.AnythingOfType("*ec2.DescribeVolumesInput")).Return(mockOutput, nil)
wrapper := &EC2Wrapper{m}
_, err := wrapper.find("label")
assert.Error(t, err, "find should return an error when more than one volume matches the label")
}
示例3: TestTagReturnsErrorWhenEC2ReturnsError
func TestTagReturnsErrorWhenEC2ReturnsError(t *testing.T) {
m := new(mocks.EC2)
m.On("CreateTags", mock.AnythingOfType("*ec2.CreateTagsInput")).Return(&ec2.CreateTagsOutput{}, fmt.Errorf("this is a mocked AWS error"))
wrapper := &EC2Wrapper{m}
err := wrapper.tag("vol-1234beef", "label")
assert.Error(t, err, "tag should return an error when AWS returns an error")
}
示例4: TestTag
func TestTag(t *testing.T) {
m := new(mocks.EC2)
m.On("CreateTags", mock.AnythingOfType("*ec2.CreateTagsInput")).Return(&ec2.CreateTagsOutput{}, nil)
wrapper := &EC2Wrapper{m}
err := wrapper.tag("vol-1234beef", "label")
assert.NoError(t, err, "tag should not return an error when all is fine")
}
示例5: TestCreateReturnsErrorWhenEC2ReturnsError
func TestCreateReturnsErrorWhenEC2ReturnsError(t *testing.T) {
m := new(mocks.EC2)
m.On("CreateVolume", mock.AnythingOfType("*ec2.CreateVolumeInput")).Return(&ec2.Volume{}, fmt.Errorf("this is a mocked AWS error"))
wrapper := &EC2Wrapper{m}
_, err := wrapper.create("label", map[string]string{})
assert.Error(t, err, "create should return an error when AWS returns an error")
}
示例6: TestFindReturnsErrorWhenEC2ReturnsError
func TestFindReturnsErrorWhenEC2ReturnsError(t *testing.T) {
mockOutput := &ec2.DescribeVolumesOutput{
Volumes: []*ec2.Volume{},
}
m := new(mocks.EC2)
m.On("DescribeVolumes", mock.AnythingOfType("*ec2.DescribeVolumesInput")).Return(mockOutput, fmt.Errorf("this is a mocked AWS error"))
wrapper := &EC2Wrapper{m}
_, err := wrapper.find("label")
assert.Error(t, err, "find should return an error when AWS returns an error")
}
示例7: TestFindReturnsEmptyStringWhenNoMatchingVolume
func TestFindReturnsEmptyStringWhenNoMatchingVolume(t *testing.T) {
mockOutput := &ec2.DescribeVolumesOutput{
Volumes: []*ec2.Volume{},
}
m := new(mocks.EC2)
m.On("DescribeVolumes", mock.AnythingOfType("*ec2.DescribeVolumesInput")).Return(mockOutput, nil)
wrapper := &EC2Wrapper{m}
output, err := wrapper.find("nosuchlabel")
if err != nil {
t.Error(err)
}
assert.Equal(t, "", output, "find should return an empty string when no volume matches DockerVolumeName=label")
}
示例8: TestCreateReturnsVolumeIdWhenCreatingVolume
func TestCreateReturnsVolumeIdWhenCreatingVolume(t *testing.T) {
optsTests := []map[string]string{
{},
{
"size": "10",
},
{
"type": "standard",
},
{
"type": "io1",
"iops": "1000",
},
}
mockOutput := &ec2.Volume{
AvailabilityZone: aws.String("eu-west-1a"),
CreateTime: aws.Time(time.Now()),
Encrypted: aws.Bool(false),
Iops: aws.Int64(3),
Size: aws.Int64(1),
SnapshotId: aws.String(""),
State: aws.String("creating"),
VolumeId: aws.String("vol-681e4aac"),
VolumeType: aws.String("gp2"),
}
m := new(mocks.EC2)
m.On("CreateVolume", mock.AnythingOfType("*ec2.CreateVolumeInput")).Return(mockOutput, nil)
wrapper := &EC2Wrapper{m}
for _, tt := range optsTests {
output, err := wrapper.create("label", tt)
if err != nil {
t.Error(err)
}
assert.Equal(t, "vol-681e4aac", output, "create should return the volumeId of the volume created")
}
}
示例9: TestFindReturnsIdWhenOneMatchingVolume
func TestFindReturnsIdWhenOneMatchingVolume(t *testing.T) {
mockOutput := &ec2.DescribeVolumesOutput{
Volumes: []*ec2.Volume{
&ec2.Volume{
AvailabilityZone: aws.String("eu-west-1a"),
CreateTime: aws.Time(time.Now()),
Encrypted: aws.Bool(false),
Iops: aws.Int64(3),
Size: aws.Int64(1),
SnapshotId: aws.String(""),
State: aws.String("available"),
Tags: []*ec2.Tag{
&ec2.Tag{
Key: aws.String("Name"),
Value: aws.String("label"),
},
&ec2.Tag{
Key: aws.String("DockerVolumeName"),
Value: aws.String("label"),
},
},
VolumeId: aws.String("vol-681e4aac"),
VolumeType: aws.String("gp2"),
},
},
}
m := new(mocks.EC2)
m.On("DescribeVolumes", mock.AnythingOfType("*ec2.DescribeVolumesInput")).Return(mockOutput, nil)
wrapper := &EC2Wrapper{m}
output, err := wrapper.find("label")
if err != nil {
t.Error(err)
}
assert.Equal(t, "vol-681e4aac", output, "find should return the volumeId of the volume matching DockerVolumeName=label")
}