Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed Dec 20, 2023
1 parent 7c5976b commit 7600b35
Show file tree
Hide file tree
Showing 43 changed files with 704 additions and 858 deletions.
1 change: 1 addition & 0 deletions .github/workflows/others_testacc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ jobs:
OUTSCALE_REGION: ${{ secrets.OSC_REGION }}
OUTSCALE_ACCOUNT: ${{ secrets.OSC_ACCOUNT_ID }}
OUTSCALE_IMAGEID: ${{ secrets.OUTSCALE_IMAGEID }}
CA_PATH: ${{ secrets.CA_PATH }}
11 changes: 6 additions & 5 deletions outscale/data_source_outscale_api_access_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -15,14 +16,15 @@ import (
func TestAccOthers_DataOutscaleOAPIApiAccessRule_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_api_access_rule.rule_data"
ca_path := os.Getenv("CA_PATH")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccDataCheckOutscaleApiAccessRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataOutscaleOAPIApiAccessRuleConfig(),
Config: testAccDataOutscaleOAPIApiAccessRuleConfig(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleApiAccessRuleExists(resourceName),
),
Expand Down Expand Up @@ -69,10 +71,10 @@ func testAccDataCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error {
return nil
}

func testAccDataOutscaleOAPIApiAccessRuleConfig() string {
func testAccDataOutscaleOAPIApiAccessRuleConfig(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_rule" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%q)
description = "Ca data test create"
}
Expand All @@ -97,6 +99,5 @@ data "outscale_api_access_rule" "api_access_rule" {
name = "descriptions"
values = ["test api access rule"]
}
}
`)
}`, path)
}
11 changes: 6 additions & 5 deletions outscale/data_source_outscale_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -14,14 +15,15 @@ import (

func TestAccOthers_DataOutscaleCa_basic(t *testing.T) {
resourceName := "outscale_ca.ca_test"
ca_path := os.Getenv("CA_PATH")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccDataCheckOutscaleCaDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataOutscaleOAPICaConfig(),
Config: testAccDataOutscaleOAPICaConfig(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleCaExists(resourceName),
),
Expand Down Expand Up @@ -70,10 +72,10 @@ func testAccDataCheckOutscaleCaDestroy(s *terraform.State) error {
return nil
}

func testAccDataOutscaleOAPICaConfig() string {
func testAccDataOutscaleOAPICaConfig(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_test" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%q)
description = "Ca testacc create"
}
Expand All @@ -82,6 +84,5 @@ data "outscale_ca" "ca_data" {
name = "ca_ids"
values = [outscale_ca.ca_test.id]
}
}
`)
}`, path)
}
13 changes: 7 additions & 6 deletions outscale/data_source_outscale_cas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -14,14 +15,15 @@ import (

func TestAccOthers_DataOutscaleCas_basic(t *testing.T) {
resName := "outscale_ca.ca_test"
ca_path := os.Getenv("CA_PATH")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccDataCheckOutscaleCasDestroy,
Steps: []resource.TestStep{
{
Config: testAccDataOutscaleOAPICasConfig(),
Config: testAccDataOutscaleOAPICasConfig(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleCaExists(resName),
),
Expand Down Expand Up @@ -70,15 +72,15 @@ func testAccDataCheckOutscaleCasDestroy(s *terraform.State) error {
return nil
}

func testAccDataOutscaleOAPICasConfig() string {
func testAccDataOutscaleOAPICasConfig(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_test" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%[1]q)
description = "Ca testacc create"
}
resource "outscale_ca" "ca_test2" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%[1]q)
description = "Ca testacc create2"
}
Expand All @@ -91,6 +93,5 @@ data "outscale_cas" "cas_data" {
name = "description"
values = ["Ca testacc create2"]
}
}
`)
}`, path)
}
2 changes: 1 addition & 1 deletion outscale/data_source_outscale_nics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func getDSOAPINicsSchema() map[string]*schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"nic_link_id": {
"link_nic_id": {
Type: schema.TypeString,
Computed: true,
},
Expand Down
22 changes: 11 additions & 11 deletions outscale/data_source_outscale_vpn_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,30 @@ func TestAccOthers_VPNConnectionDataSource_withFilters(t *testing.T) {

func testAccOutscaleVPNConnectionDataSourceConfigBasic(publicIP string) string {
return fmt.Sprintf(`
resource "outscale_virtual_gateway" "virtual_gateway" {
resource "outscale_virtual_gateway" "virtual_gateway1" {
connection_type = "ipsec.1"
}
resource "outscale_client_gateway" "customer_gateway" {
resource "outscale_client_gateway" "customer_gateway1" {
bgp_asn = 3
public_ip = "%s"
connection_type = "ipsec.1"
}
resource "outscale_vpn_connection" "foo" {
client_gateway_id = "${outscale_client_gateway.customer_gateway.id}"
virtual_gateway_id = "${outscale_virtual_gateway.virtual_gateway.id}"
resource "outscale_vpn_connection" "foo1" {
client_gateway_id = outscale_client_gateway.customer_gateway1.id
virtual_gateway_id = outscale_virtual_gateway.virtual_gateway1.id
connection_type = "ipsec.1"
static_routes_only = true
tags {
key = "Name"
value = "test-VPN"
key = "Name"
value = "test-VPN"
}
}
data "outscale_vpn_connection" "test" {
vpn_connection_id = "${outscale_vpn_connection.foo.id}"
vpn_connection_id = outscale_vpn_connection.foo1.id
}
`, publicIP)
}
Expand All @@ -81,16 +81,16 @@ func testAccOutscaleVPNConnectionDataSourceConfigWithFilters(publicIP string) st
}
resource "outscale_vpn_connection" "foo" {
client_gateway_id = "${outscale_client_gateway.customer_gateway.id}"
virtual_gateway_id = "${outscale_virtual_gateway.virtual_gateway.id}"
client_gateway_id = outscale_client_gateway.customer_gateway.id
virtual_gateway_id = outscale_virtual_gateway.virtual_gateway.id
connection_type = "ipsec.1"
static_routes_only = true
}
data "outscale_vpn_connection" "test" {
filter {
name = "vpn_connection_ids"
values = ["${outscale_vpn_connection.foo.id}"]
values = [outscale_vpn_connection.foo.id]
}
}
`, publicIP)
Expand Down
11 changes: 5 additions & 6 deletions outscale/instance_set_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package outscale
import (
"bytes"
"fmt"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
oscgo "github.com/outscale/osc-sdk-go/v2"
Expand All @@ -30,15 +29,15 @@ func getOAPILinkNicLight(l oscgo.LinkNicLight) []map[string]interface{} {
}}
}

func getOAPILinkNic(l oscgo.LinkNic) map[string]interface{} {
return map[string]interface{}{
"delete_on_vm_deletion": strconv.FormatBool(l.GetDeleteOnVmDeletion()),
"device_number": fmt.Sprintf("%d", l.GetDeviceNumber()),
func getOAPILinkNic(l oscgo.LinkNic) []map[string]interface{} {
return []map[string]interface{}{{
"delete_on_vm_deletion": l.GetDeleteOnVmDeletion(),
"device_number": l.GetDeviceNumber(),
"link_nic_id": l.GetLinkNicId(),
"state": l.GetState(),
"vm_account_id": l.GetVmAccountId(),
"vm_id": l.GetVmId(),
}
}}
}

func getOAPIBsuSet(bsu oscgo.BsuCreated) []map[string]interface{} {
Expand Down
11 changes: 6 additions & 5 deletions outscale/resource_outscale_api_access_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -15,14 +16,15 @@ import (
func TestAccOthers_AccessRule_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_api_access_rule.rule_test"
ca_path := os.Getenv("CA_PATH")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOutscaleApiAccessRuleDestroy,
Steps: []resource.TestStep{
{
Config: testAccOutscaleOAPIApiAccessRuleConfig(),
Config: testAccOutscaleOAPIApiAccessRuleConfig(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleApiAccessRuleExists(resourceName),
),
Expand Down Expand Up @@ -115,17 +117,16 @@ func testAccCheckOutscaleApiAccessRuleDestroy(s *terraform.State) error {
return nil
}

func testAccOutscaleOAPIApiAccessRuleConfig() string {
func testAccOutscaleOAPIApiAccessRuleConfig(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_rule" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%q)
description = "Ca testacc create"
}
resource "outscale_api_access_rule" "rule_test" {
ca_ids = [outscale_ca.ca_rule.id]
ip_ranges = ["192.0.2.0/16"]
description = "testing api access rule"
}
`)
}`, path)
}
20 changes: 10 additions & 10 deletions outscale/resource_outscale_ca_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand All @@ -15,20 +16,21 @@ import (
func TestAccOthers_Ca_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_ca.ca_test"
ca_path := os.Getenv("CA_PATH")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckOutscaleCaDestroy,
Steps: []resource.TestStep{
{
Config: testAccOutscaleOAPICaConfig(),
Config: testAccOutscaleOAPICaConfig(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleCaExists(resourceName),
),
},
{
Config: testAccOutscaleOAPICaConfigUpdateDescription(),
Config: testAccOutscaleOAPICaConfigUpdateDescription(ca_path),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleCaExists(resourceName),
),
Expand Down Expand Up @@ -120,20 +122,18 @@ func testAccCheckOutscaleCaDestroy(s *terraform.State) error {
return nil
}

func testAccOutscaleOAPICaConfig() string {
func testAccOutscaleOAPICaConfig(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_test" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%q)
description = "Ca testacc create"
}
`)
}`, path)
}

func testAccOutscaleOAPICaConfigUpdateDescription() string {
func testAccOutscaleOAPICaConfigUpdateDescription(path string) string {
return fmt.Sprintf(`
resource "outscale_ca" "ca_test" {
ca_pem = file("./test-cert.pem")
ca_pem = file(%q)
description = "Ca testacc update"
}
`)
}`, path)
}
4 changes: 2 additions & 2 deletions outscale/resource_outscale_flexible_gpu_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ func testAccOutscaleOAPIFlexibleGpuLinkConfig(omi, vmType, region string) string
resource "outscale_flexible_gpu" "fGPU-1" {
model_name = "nvidia-p6"
generation = "v5"
subregion_name = "%[3]s"
subregion_name = "%[3]sa"
delete_on_vm_deletion = true
}
resource "outscale_flexible_gpu" "fGPU-2" {
model_name = "nvidia-p6"
generation = "v5"
subregion_name = "%[3]s"
subregion_name = "%[3]sa"
delete_on_vm_deletion = true
}
resource "outscale_flexible_gpu_link" "link_fGPU" {
Expand Down
8 changes: 4 additions & 4 deletions outscale/resource_outscale_load_balancer_vms_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func testAccOutscaleOAPILBUAttachmentConfig1(num int, omi, region string) string
return fmt.Sprintf(`
resource "outscale_load_balancer" "bar" {
load_balancer_name = "load-test-%d"
subregion_names = ["%sa"]
subregion_names = ["%[2]sa"]
listeners {
backend_port = 8000
backend_protocol = "HTTP"
Expand All @@ -62,12 +62,12 @@ resource "outscale_load_balancer" "bar" {
}
resource "outscale_vm" "foo1" {
image_id = "%[2]s"
image_id = "%[3]s"
vm_type = "tinav4.c1r1p1"
}
resource "outscale_vm" "foo2" {
image_id = "%[2]s"
image_id = "%[3]s"
vm_type = "tinav4.c1r1p1"
}
Expand All @@ -82,7 +82,7 @@ func testAcc_ConfigLBUAttachmentAddUpdate(omi, region string) string {
return fmt.Sprintf(`
resource "outscale_load_balancer" "bar" {
load_balancer_name = "load-test12"
subregion_names = ["%sa"]
subregion_names = ["%[1]sa"]
listeners {
backend_port = 8000
backend_protocol = "HTTP"
Expand Down
Loading

0 comments on commit 7600b35

Please sign in to comment.