test: fix unit test in block device security group and build info
This commit is contained in:
parent
2f87427fd4
commit
e8ef12e41c
|
@ -7,10 +7,10 @@ import (
|
|||
"github.com/outscale/osc-go/oapi"
|
||||
)
|
||||
|
||||
func TestBlockDevice(t *testing.T) {
|
||||
func TestBlockDevice_LaunchDevices(t *testing.T) {
|
||||
cases := []struct {
|
||||
Config *BlockDevice
|
||||
Result *oapi.BlockDeviceMapping
|
||||
Result oapi.BlockDeviceMappingVmCreation
|
||||
}{
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
|
@ -21,9 +21,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
SnapshotId: "snap-1234",
|
||||
VolumeType: "standard",
|
||||
VolumeSize: 8,
|
||||
|
@ -37,9 +37,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
VolumeSize: 8,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: false,
|
||||
},
|
||||
|
@ -54,9 +54,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
IOPS: 1000,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "io1",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
|
@ -72,9 +72,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
|
@ -89,9 +89,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
|
@ -105,9 +105,9 @@ func TestBlockDevice(t *testing.T) {
|
|||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.Bsu{
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "standard",
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
@ -119,7 +119,7 @@ func TestBlockDevice(t *testing.T) {
|
|||
VirtualName: "ephemeral0",
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
VirtualDeviceName: "ephemeral0",
|
||||
},
|
||||
|
@ -130,34 +130,168 @@ func TestBlockDevice(t *testing.T) {
|
|||
NoDevice: true,
|
||||
},
|
||||
|
||||
Result: &oapi.BlockDeviceMapping{
|
||||
Result: oapi.BlockDeviceMappingVmCreation{
|
||||
DeviceName: "/dev/sdb",
|
||||
NoDevice: "",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
|
||||
launchBlockDevices := LaunchBlockDevices{
|
||||
LaunchMappings: []BlockDevice{*tc.Config},
|
||||
}
|
||||
|
||||
expected := []oapi.BlockDeviceMappingVmCreation{tc.Result}
|
||||
|
||||
launchResults := launchBlockDevices.BuildLaunchDevices()
|
||||
if !reflect.DeepEqual(expected, launchResults) {
|
||||
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
||||
expected, launchResults)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockDevice_OMI(t *testing.T) {
|
||||
cases := []struct {
|
||||
Config *BlockDevice
|
||||
Result oapi.BlockDeviceMappingImage
|
||||
}{
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
SnapshotId: "snap-1234",
|
||||
VolumeType: "standard",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
SnapshotId: "snap-1234",
|
||||
VolumeType: "standard",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeSize: 8,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "io1",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
IOPS: 1000,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "io1",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
Iops: 1000,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "gp2",
|
||||
VolumeSize: 8,
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VolumeType: "standard",
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
Bsu: oapi.BsuToCreate{
|
||||
VolumeType: "standard",
|
||||
DeleteOnVmDeletion: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
VirtualName: "ephemeral0",
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
VirtualDeviceName: "ephemeral0",
|
||||
},
|
||||
},
|
||||
{
|
||||
Config: &BlockDevice{
|
||||
DeviceName: "/dev/sdb",
|
||||
},
|
||||
|
||||
Result: oapi.BlockDeviceMappingImage{
|
||||
DeviceName: "/dev/sdb",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
omiBlockDevices := OMIBlockDevices{
|
||||
OMIMappings: []BlockDevice{*tc.Config},
|
||||
}
|
||||
|
||||
launchBlockDevices := LaunchBlockDevices{
|
||||
LaunchMappings: []BlockDevice{*tc.Config},
|
||||
}
|
||||
|
||||
expected := []*oapi.BlockDeviceMapping{tc.Result}
|
||||
expected := []oapi.BlockDeviceMappingImage{tc.Result}
|
||||
|
||||
omiResults := omiBlockDevices.BuildOMIDevices()
|
||||
if !reflect.DeepEqual(expected, omiResults) {
|
||||
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
||||
expected, omiResults)
|
||||
}
|
||||
|
||||
launchResults := launchBlockDevices.BuildLaunchDevices()
|
||||
if !reflect.DeepEqual(expected, launchResults) {
|
||||
t.Fatalf("Bad block device, \nexpected: %#v\n\ngot: %#v",
|
||||
expected, launchResults)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/outscale/osc-go/oapi"
|
||||
)
|
||||
|
||||
func testImage() *oapi.Image {
|
||||
return &oapi.Image{
|
||||
func testImage() oapi.Image {
|
||||
return oapi.Image{
|
||||
ImageId: "ami-abcd1234",
|
||||
ImageName: "ami_test_name",
|
||||
Tags: []oapi.ResourceTag{
|
||||
|
|
|
@ -121,7 +121,7 @@ func (s *StepSecurityGroup) Run(_ context.Context, state multistep.StateBag) mul
|
|||
SecurityGroupId: groupResp.OK.SecurityGroup.SecurityGroupId,
|
||||
Flow: "Inbound",
|
||||
Rules: []oapi.SecurityGroupRule{
|
||||
oapi.SecurityGroupRule{
|
||||
{
|
||||
FromPortRange: int64(port),
|
||||
ToPortRange: int64(port),
|
||||
IpRanges: []string{s.TemporarySGSourceCidr},
|
||||
|
|
Loading…
Reference in New Issue