From ab03126a161cbb877a0653f5a1e79f62d3387546 Mon Sep 17 00:00:00 2001 From: Thiery Ouattara Date: Thu, 31 Oct 2024 10:21:35 +0000 Subject: [PATCH] Fix some tests and refactoring --- outscale/data_source_outscale_vm.go | 2 +- .../data_source_outscale_vm_types_test.go | 2 +- outscale/resource_outscale_access_key_test.go | 22 ++++++++++++------- .../resource_outscale_load_balancer_vms.go | 2 +- ...cer_vm_health_datasource_attributes_ok.ref | 1 + utils/utils.go | 6 ++--- 6 files changed, 21 insertions(+), 14 deletions(-) diff --git a/outscale/data_source_outscale_vm.go b/outscale/data_source_outscale_vm.go index ec816123f..e97bd14d4 100644 --- a/outscale/data_source_outscale_vm.go +++ b/outscale/data_source_outscale_vm.go @@ -28,7 +28,7 @@ func DataSourceOutscaleVMRead(d *schema.ResourceData, meta interface{}) error { instanceID, instanceIDOk := d.GetOk("vm_id") var err error if !filtersOk && !instanceIDOk { - return fmt.Errorf("One of filters, or instance_id must be assigned") + return fmt.Errorf("one of filters, or instance_id must be assigned") } // Build up search parameters params := oscgo.ReadVmsRequest{} diff --git a/outscale/data_source_outscale_vm_types_test.go b/outscale/data_source_outscale_vm_types_test.go index 328e8c8c5..cb8d5effe 100644 --- a/outscale/data_source_outscale_vm_types_test.go +++ b/outscale/data_source_outscale_vm_types_test.go @@ -19,7 +19,7 @@ func TestAccVM_TypesDataSource_basic(t *testing.T) { Providers: testAccProviders, Steps: []resource.TestStep{ { - Config: testAccDataSourceOutscaleVMTypesConfig(omi, "tinav4.c1r1p1"), + Config: testAccDataSourceOutscaleVMTypesConfig(omi, "tinav5.c2r2p2"), }, }, }) diff --git a/outscale/resource_outscale_access_key_test.go b/outscale/resource_outscale_access_key_test.go index 8e0fe308a..77af4f01a 100644 --- a/outscale/resource_outscale_access_key_test.go +++ b/outscale/resource_outscale_access_key_test.go @@ -170,12 +170,15 @@ func testAccCheckOutscaleAccessKeyExists(resourceName string) resource.TestCheck return fmt.Errorf("No Access ID is set") } conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI - - filter := oscgo.ReadSecretAccessKeyRequest{ - AccessKeyId: rs.Primary.ID, + filter := oscgo.FiltersAccessKeys{ + AccessKeyIds: &[]string{rs.Primary.ID}, + } + req := oscgo.ReadAccessKeysRequest{ + Filters: &filter, } + err := resource.Retry(2*time.Minute, func() *resource.RetryError { - _, httpResp, err := conn.AccessKeyApi.ReadSecretAccessKey(context.Background()).ReadSecretAccessKeyRequest(filter).Execute() + _, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute() if err != nil { return utils.CheckThrottling(httpResp, err) } @@ -195,12 +198,15 @@ func testAccCheckOutscaleAccessKeyDestroy(s *terraform.State) error { if rs.Type != "outscale_access_key" { continue } - - filter := oscgo.ReadSecretAccessKeyRequest{ - AccessKeyId: rs.Primary.ID, + filter := oscgo.FiltersAccessKeys{ + AccessKeyIds: &[]string{rs.Primary.ID}, + } + req := oscgo.ReadAccessKeysRequest{ + Filters: &filter, } + err := resource.Retry(2*time.Minute, func() *resource.RetryError { - _, httpResp, err := conn.AccessKeyApi.ReadSecretAccessKey(context.Background()).ReadSecretAccessKeyRequest(filter).Execute() + _, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute() if err != nil { return utils.CheckThrottling(httpResp, err) } diff --git a/outscale/resource_outscale_load_balancer_vms.go b/outscale/resource_outscale_load_balancer_vms.go index 3cbd340d7..998d68c9e 100644 --- a/outscale/resource_outscale_load_balancer_vms.go +++ b/outscale/resource_outscale_load_balancer_vms.go @@ -50,7 +50,7 @@ func ResourceLBUAttachmentCreate(d *schema.ResourceData, meta interface{}) error vmIds := utils.SetToStringSlice(d.Get("backend_vm_ids").(*schema.Set)) vmIps := d.Get("backend_ips").(*schema.Set) if len(vmIds) == 0 && vmIps.Len() == 0 { - return fmt.Errorf("Error: the 'backend_vm_ids' and 'backend_ips' parameters cannot both be empty") + return fmt.Errorf("error: the 'backend_vm_ids' and 'backend_ips' parameters cannot both be empty") } if vmIps.Len() > 0 { vm_ips, err := getVmIdsThroughVmIps(conn, vmIps) diff --git a/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref b/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref index 556b9a0bd..3190caae9 100644 --- a/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref +++ b/tests/qa_provider_oapi/data/load_balancer_vm_health/TF-92_load_balancer_vm_health_datasource_attributes_ok/step1.load_balancer_vm_health_datasource_attributes_ok.ref @@ -212,6 +212,7 @@ { "schema_version": 0, "attributes": { + "backend_ips": null, "backend_vm_ids": [ "##id-0##" ], diff --git a/utils/utils.go b/utils/utils.go index 51fc07512..409888008 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -154,7 +154,7 @@ func StringSliceToFloat32Slice(src []string) (res []float32) { } func LogManuallyDeleted(name, id string) { - log.Printf("[WARN] %s %s not found, probably deleted manually, removing from state", name, id) + log.Printf("\n[WARN] %s %s not found, probably deleted manually, removing from state\n", name, id) } func IsResponseEmpty(len int, name, id string) bool { @@ -167,10 +167,10 @@ func IsResponseEmpty(len int, name, id string) bool { func IsResponseEmptyOrMutiple(rLen int, resName string) error { if rLen == 0 { - return fmt.Errorf("Unable to find %v", resName) + return fmt.Errorf("unable to find %v", resName) } if rLen > 1 { - return fmt.Errorf("Multiple %vs matched; use additional constraints to reduce matches to a single %v", resName, resName) + return fmt.Errorf("multiple %vs matched; use additional constraints to reduce matches to a single %v", resName, resName) } return nil }