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 6, 2024
1 parent d6f5760 commit ab03126
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion outscale/data_source_outscale_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
2 changes: 1 addition & 1 deletion outscale/data_source_outscale_vm_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
},
})
Expand Down
22 changes: 14 additions & 8 deletions outscale/resource_outscale_access_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion outscale/resource_outscale_load_balancer_vms.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
{
"schema_version": 0,
"attributes": {
"backend_ips": null,
"backend_vm_ids": [
"##id-0##"
],
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit ab03126

Please sign in to comment.