From a40d52c6b0c4c8731477db9842e7fc6ed879b4a6 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Wed, 23 Oct 2024 15:34:51 +0000 Subject: [PATCH] Fix some tests and refactoring --- outscale/data_source_outscale_net_test.go | 4 ++-- outscale/data_source_outscale_nic.go | 6 +----- outscale/data_source_outscale_route_tables.go | 4 ---- outscale/data_source_outscale_virtual_gateway_test.go | 6 ++---- outscale/data_source_outscale_virtual_gateways_test.go | 7 ++----- outscale/resource_outscale_route_table_link.go | 4 ---- outscale/resource_outscale_security_group_test.go | 7 ++----- ...urce_outscale_virtual_gateway_route_propagation_test.go | 5 ++--- outscale/resource_outscale_vm.go | 4 ++-- outscale/resource_outscale_volume_link_test.go | 5 ++--- 10 files changed, 15 insertions(+), 37 deletions(-) diff --git a/outscale/data_source_outscale_net_test.go b/outscale/data_source_outscale_net_test.go index 711810e93..8023d3dd3 100644 --- a/outscale/data_source_outscale_net_test.go +++ b/outscale/data_source_outscale_net_test.go @@ -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 { diff --git a/outscale/data_source_outscale_nic.go b/outscale/data_source_outscale_nic.go index f49a10025..a010c6310 100644 --- a/outscale/data_source_outscale_nic.go +++ b/outscale/data_source_outscale_nic.go @@ -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 diff --git a/outscale/data_source_outscale_route_tables.go b/outscale/data_source_outscale_route_tables.go index 3889dae92..256b99096 100644 --- a/outscale/data_source_outscale_route_tables.go +++ b/outscale/data_source_outscale_route_tables.go @@ -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") diff --git a/outscale/data_source_outscale_virtual_gateway_test.go b/outscale/data_source_outscale_virtual_gateway_test.go index 681e9f6d5..a17606fbf 100644 --- a/outscale/data_source_outscale_virtual_gateway_test.go +++ b/outscale/data_source_outscale_virtual_gateway_test.go @@ -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() { @@ -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", @@ -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" diff --git a/outscale/data_source_outscale_virtual_gateways_test.go b/outscale/data_source_outscale_virtual_gateways_test.go index bb78b7792..89fa0b747 100644 --- a/outscale/data_source_outscale_virtual_gateways_test.go +++ b/outscale/data_source_outscale_virtual_gateways_test.go @@ -4,15 +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_DataSourceVpnGateways_unattached(t *testing.T) { //t.Skip() t.Parallel() - rInt := acctest.RandInt() - resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) @@ -20,13 +17,13 @@ func TestAccOthers_DataSourceVpnGateways_unattached(t *testing.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" diff --git a/outscale/resource_outscale_route_table_link.go b/outscale/resource_outscale_route_table_link.go index 31ea79428..a7f334e27 100644 --- a/outscale/resource_outscale_route_table_link.go +++ b/outscale/resource_outscale_route_table_link.go @@ -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 { diff --git a/outscale/resource_outscale_security_group_test.go b/outscale/resource_outscale_security_group_test.go index 738505d5f..f6d52cc0b 100644 --- a/outscale/resource_outscale_security_group_test.go +++ b/outscale/resource_outscale_security_group_test.go @@ -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{ @@ -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)), ), @@ -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 diff --git a/outscale/resource_outscale_virtual_gateway_route_propagation_test.go b/outscale/resource_outscale_virtual_gateway_route_propagation_test.go index bf3a06869..2abc83bc1 100644 --- a/outscale/resource_outscale_virtual_gateway_route_propagation_test.go +++ b/outscale/resource_outscale_virtual_gateway_route_propagation_test.go @@ -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() { @@ -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", @@ -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" diff --git a/outscale/resource_outscale_vm.go b/outscale/resource_outscale_vm.go index ea253bfcc..7814a7de4 100644 --- a/outscale/resource_outscale_vm.go +++ b/outscale/resource_outscale_vm.go @@ -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 } @@ -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), diff --git a/outscale/resource_outscale_volume_link_test.go b/outscale/resource_outscale_volume_link_test.go index fa6d9ede3..c62ae94dc 100644 --- a/outscale/resource_outscale_volume_link_test.go +++ b/outscale/resource_outscale_volume_link_test.go @@ -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() { @@ -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), ), }, }, @@ -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 {