Skip to content

Commit

Permalink
Fix some tests and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Nov 14, 2024
1 parent 3304231 commit 6f6e13b
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 37 deletions.
4 changes: 2 additions & 2 deletions outscale/data_source_outscale_net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ func TestAccNet_DataSource_basic(t *testing.T) {
{
Config: testAccDataSourceOutscaleVpcConfig(ipRange, tag),
Check: resource.ComposeTestCheckFunc(
testAccDataSourceOutscaleVpcCheck("data.outscale_net.by_id", ipRange, tag),
testAccDataSourceOutscaleVpcCheck("data.outscale_net.by_id", ipRange),
),
},
},
})
}

func testAccDataSourceOutscaleVpcCheck(name, ipRange, tag string) resource.TestCheckFunc {
func testAccDataSourceOutscaleVpcCheck(name, ipRange string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[name]
if !ok {
Expand Down
6 changes: 1 addition & 5 deletions outscale/data_source_outscale_nic.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,17 +244,13 @@ func DataSourceOutscaleNicRead(d *schema.ResourceData, meta interface{}) error {
return nil
})

if err != nil {
return fmt.Errorf("Error describing Network Interfaces : %s", err)
}

if err != nil {
if statusCode == http.StatusNotFound {
// The ENI is gone now, so just remove it from the state
d.SetId("")
return nil
}
return fmt.Errorf("Error retrieving ENI: %s", err)
return fmt.Errorf("Error describing Network Interfaces: %s", err)
}
if err := utils.IsResponseEmptyOrMutiple(len(resp.GetNics()), "Nic"); err != nil {
return err
Expand Down
4 changes: 0 additions & 4 deletions outscale/data_source_outscale_route_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ func DataSourceOutscaleRouteTablesRead(d *schema.ResourceData, meta interface{})
return fmt.Errorf("[DEBUG] Error reading Internet Services (%s)", errString)
}

if err != nil {
return err
}

rt := resp.GetRouteTables()
if len(rt) == 0 {
return fmt.Errorf("your query returned no results, please change your search criteria and try again")
Expand Down
6 changes: 2 additions & 4 deletions outscale/data_source_outscale_virtual_gateway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_DataSourceVirtualGateway_unattached(t *testing.T) {
//t.Skip()
t.Parallel()
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -20,7 +18,7 @@ func TestAccOthers_DataSourceVirtualGateway_unattached(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceOutscaleVirtualGatewayUnattachedConfig(rInt),
Config: testAccDataSourceOutscaleVirtualGatewayUnattachedConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(
"data.outscale_virtual_gateway.test_by_id", "id",
Expand All @@ -33,7 +31,7 @@ func TestAccOthers_DataSourceVirtualGateway_unattached(t *testing.T) {
})
}

func testAccDataSourceOutscaleVirtualGatewayUnattachedConfig(rInt int) string {
func testAccDataSourceOutscaleVirtualGatewayUnattachedConfig() string {
return fmt.Sprintf(`
resource "outscale_virtual_gateway" "unattached" {
connection_type = "ipsec.1"
Expand Down
7 changes: 2 additions & 5 deletions outscale/data_source_outscale_virtual_gateways_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccOthers_DataSourceVpnGateways_unattached(t *testing.T) {
//t.Skip()
t.Parallel()
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceOutscaleVpnGatewaysUnattachedConfig(rInt),
Config: testAccDataSourceOutscaleVpnGatewaysUnattachedConfig(),
},
},
})
}

func testAccDataSourceOutscaleVpnGatewaysUnattachedConfig(rInt int) string {
func testAccDataSourceOutscaleVpnGatewaysUnattachedConfig() string {
return fmt.Sprintf(`
resource "outscale_virtual_gateway" "unattached" {
connection_type = "ipsec.1"
Expand Down
4 changes: 0 additions & 4 deletions outscale/resource_outscale_route_table_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ func ResourceOutscaleLinkRouteTableCreate(d *schema.ResourceData, meta interface
resp = rp
return nil
})
if err != nil {
return err
}

// Set the ID and return
var errString string
if err != nil {
Expand Down
7 changes: 2 additions & 5 deletions outscale/resource_outscale_security_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import (
"fmt"
"testing"

oscgo "github.com/outscale/osc-sdk-go/v2"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccNet_WithSecurityGroup(t *testing.T) {
var group oscgo.SecurityGroup
rInt := acctest.RandInt()

resource.Test(t, resource.TestCase{
Expand All @@ -23,7 +20,7 @@ func TestAccNet_WithSecurityGroup(t *testing.T) {
{
Config: testAccOutscaleSecurityGroupConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleSecurityGroupRuleExists("outscale_security_group.web", &group),
testAccCheckOutscaleSecurityGroupRuleExists("outscale_security_group.web"),
resource.TestCheckResourceAttr(
"outscale_security_group.web", "security_group_name", fmt.Sprintf("terraform_test_%d", rInt)),
),
Expand All @@ -48,7 +45,7 @@ func testAccCheckOutscaleSGRuleDestroy(s *terraform.State) error {
return nil
}

func testAccCheckOutscaleSecurityGroupRuleExists(n string, group *oscgo.SecurityGroup) resource.TestCheckFunc {
func testAccCheckOutscaleSecurityGroupRuleExists(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

func TestAccNet_WithVirtualRoutePropagation_basic(t *testing.T) {
t.Parallel()
rBgpAsn := utils.RandIntRange(64512, 65534)

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -25,7 +24,7 @@ func TestAccNet_WithVirtualRoutePropagation_basic(t *testing.T) {
CheckDestroy: testAccCheckOAPIVirtualRoutePropagationDestroy,
Steps: []resource.TestStep{
{
Config: testAccOutscaleVpnRoutePropagationConfig(rBgpAsn),
Config: testAccOutscaleVpnRoutePropagationConfig(),
Check: resource.ComposeTestCheckFunc(
testAccOutscaleVpnRoutePropagation(
"outscale_virtual_gateway_route_propagation.outscale_virtual_gateway_route_propagation",
Expand Down Expand Up @@ -97,7 +96,7 @@ func testAccOutscaleVpnRoutePropagation(routeProp string) resource.TestCheckFunc
}
}

func testAccOutscaleVpnRoutePropagationConfig(rBgpAsn int) string {
func testAccOutscaleVpnRoutePropagationConfig() string {
return fmt.Sprintf(`
resource "outscale_virtual_gateway" "outscale_virtual_gateway" {
connection_type = "ipsec.1"
Expand Down
4 changes: 2 additions & 2 deletions outscale/resource_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func ResourceOutscaleVM() *schema.Resource {
func resourceOAPIVMCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*OutscaleClient).OSCAPI

vmOpts, bsuMapsTags, err := buildCreateVmsRequest(d, meta)
vmOpts, bsuMapsTags, err := buildCreateVmsRequest(d)
if err != nil {
return err
}
Expand Down Expand Up @@ -1164,7 +1164,7 @@ func resourceOAPIVMDelete(d *schema.ResourceData, meta interface{}) error {
return nil
}

func buildCreateVmsRequest(d *schema.ResourceData, meta interface{}) (oscgo.CreateVmsRequest, []map[string]interface{}, error) {
func buildCreateVmsRequest(d *schema.ResourceData) (oscgo.CreateVmsRequest, []map[string]interface{}, error) {
request := oscgo.CreateVmsRequest{
DeletionProtection: oscgo.PtrBool(d.Get("deletion_protection").(bool)),
BootOnCreation: oscgo.PtrBool(true),
Expand Down
5 changes: 2 additions & 3 deletions outscale/resource_outscale_volume_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ func TestAccVM_WithVolumeAttachment_basic(t *testing.T) {
keypair := os.Getenv("OUTSCALE_KEYPAIR")

var i oscgo.Vm
var v oscgo.Volume

resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -35,7 +34,7 @@ func TestAccVM_WithVolumeAttachment_basic(t *testing.T) {
"outscale_volume_link.ebs_att", "device_name", "/dev/sdh"),
testAccCheckOutscaleVMExists("outscale_vm.web", &i),
testAccCheckOAPIVolumeAttachmentExists(
"outscale_volume_link.ebs_att", &i, &v),
"outscale_volume_link.ebs_att", &i),
),
},
},
Expand Down Expand Up @@ -86,7 +85,7 @@ func testAccCheckOAPIVolumeAttachmentDestroy(s *terraform.State) error {
return nil
}

func testAccCheckOAPIVolumeAttachmentExists(n string, i *oscgo.Vm, v *oscgo.Volume) resource.TestCheckFunc {
func testAccCheckOAPIVolumeAttachmentExists(n string, i *oscgo.Vm) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
Expand Down

0 comments on commit 6f6e13b

Please sign in to comment.