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