Skip to content

Commit

Permalink
Fix acceptance and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
outscale-toa committed May 17, 2024
1 parent 9ee1047 commit 1ca482d
Show file tree
Hide file tree
Showing 92 changed files with 782 additions and 728 deletions.
10 changes: 6 additions & 4 deletions outscale/data_source_outscale_access_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ func TestAccOthers_DatasourceAccessKey_basic(t *testing.T) {
dataSourceName := "outscale_access_key.access_key_basic"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAccessKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccClientAccessKeyDataSourceBasic(),
Expand All @@ -33,8 +34,9 @@ func TestAccOthers_AccessKey_withFilters(t *testing.T) {
dataSourceName := "outscale_access_key.keyFilters"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAccessKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccClientAccessKeyDataSourceWithFilters(),
Expand Down
83 changes: 67 additions & 16 deletions outscale/data_source_outscale_access_keys_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
package outscale

import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/outscale/terraform-provider-outscale/utils"
)

func TestAccOthers_DataSourceAccessKeys_basic(t *testing.T) {
t.Parallel()
dataSourceName := "data.outscale_access_keys.outscale_access_key"
dataSourceName := "data.outscale_access_keys.read_access_key"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAccessKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccClientAccessKeysDataSourceBasic(),
Expand All @@ -27,11 +34,12 @@ func TestAccOthers_DataSourceAccessKeys_basic(t *testing.T) {

func TestAccOthers_DataSourceAccessKeys_withFilters(t *testing.T) {
t.Parallel()
dataSourceName := "data.outscale_access_keys.outscale_access_key"
dataSourceName := "data.outscale_access_keys.filters_access_key"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAccessKeyDestroy,
Steps: []resource.TestStep{
{
Config: testAccClientAccessKeysDataSourceWithFilters(),
Expand All @@ -44,25 +52,68 @@ func TestAccOthers_DataSourceAccessKeys_withFilters(t *testing.T) {
})
}

func testAccCheckAccessKeyDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*OutscaleClient).OSCAPI

for _, rs := range s.RootModule().Resources {
if rs.Type != "outscale_access_key" {
continue
}
req := oscgo.ReadAccessKeysRequest{}
req.Filters = &oscgo.FiltersAccessKeys{
AccessKeyIds: &[]string{rs.Primary.ID},
}

var resp oscgo.ReadAccessKeysResponse
var err error
exists := false
err = resource.Retry(120*time.Second, func() *resource.RetryError {
rp, httpResp, err := conn.AccessKeyApi.ReadAccessKeys(context.Background()).ReadAccessKeysRequest(req).Execute()
if err != nil {
return utils.CheckThrottling(httpResp, err)
}
resp = rp
return nil
})
if err != nil {
return fmt.Errorf("AccessKeys reading (%s)", rs.Primary.ID)
}

for _, ca := range resp.GetAccessKeys() {
if ca.GetAccessKeyId() == rs.Primary.ID {
exists = true
}
}

if exists {
return fmt.Errorf("Access_Key still exists (%s)", rs.Primary.ID)
}
}
return nil
}

func testAccClientAccessKeysDataSourceBasic() string {
return `
resource "outscale_access_key" "outscale_access_key" {}
creationDate := time.Now().AddDate(1, 1, 0).Format("2006-01-02")
return fmt.Sprintf(`
resource "outscale_access_key" "data_access_key" {
expiration_date = "%s"
}
data "outscale_access_keys" "outscale_access_key" {
access_key_ids = [outscale_access_key.outscale_access_key.id]
data "outscale_access_keys" "read_access_key" {
access_key_ids = [outscale_access_key.data_access_key.id]
}
`
`, creationDate)
}

func testAccClientAccessKeysDataSourceWithFilters() string {
return `
resource "outscale_access_key" "outscale_access_key" {}
return fmt.Sprintf(`
resource "outscale_access_key" "datas_access_key" {}
data "outscale_access_keys" "outscale_access_key" {
data "outscale_access_keys" "filters_access_key" {
filter {
name = "access_key_ids"
values = [outscale_access_key.outscale_access_key.id]
values = [outscale_access_key.datas_access_key.id]
}
}
`
`)
}
6 changes: 2 additions & 4 deletions outscale/data_source_outscale_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,10 @@ func DataSourceOutscaleSnapshotRead(d *schema.ResourceData, meta interface{}) er
}
}
if ownersOk {
filter.SetAccountIds([]string{owners.(string)})
params.SetFilters(filter)
params.Filters.SetAccountIds([]string{owners.(string)})
}
if snapshotIdsOk {
filter.SetSnapshotIds([]string{snapshotIds.(string)})
params.SetFilters(filter)
params.Filters.SetSnapshotIds([]string{snapshotIds.(string)})
}

var resp oscgo.ReadSnapshotsResponse
Expand Down
24 changes: 13 additions & 11 deletions outscale/data_source_outscale_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package outscale
import (
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
Expand All @@ -19,7 +20,7 @@ func TestAccOthers_SnapshotDataSource_basic(t *testing.T) {
{
Config: testAccCheckOutscaleSnapshotDataSourceConfig(utils.GetRegion()),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleSnapshotDataSourceID("data.outscale_snapshot.snapshot"),
testAccCheckOutscaleSnapshotDataSourceID("data.outscale_snapshot.snapshot_test"),
resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "1"),
),
},
Expand All @@ -37,8 +38,8 @@ func TestAccOthers_SnapshotDataSource_multipleFilters(t *testing.T) {
{
Config: testAccCheckOutscaleSnapshotDataSourceConfigWithMultipleFilters(utils.GetRegion()),
Check: resource.ComposeTestCheckFunc(
testAccCheckOutscaleSnapshotDataSourceID("data.outscale_snapshot.snapshot"),
resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot", "volume_size", "10"),
testAccCheckOutscaleSnapshotDataSourceID("data.outscale_snapshot.snapshot_filters"),
resource.TestCheckResourceAttr("data.outscale_snapshot.snapshot_filters", "volume_size", "10"),
),
},
},
Expand Down Expand Up @@ -66,38 +67,39 @@ func testAccCheckOutscaleSnapshotDataSourceConfig(region string) string {
size = 1
}
resource "outscale_snapshot" "snapshot" {
resource "outscale_snapshot" "snapshot_01" {
volume_id = outscale_volume.example.id
}
data "outscale_snapshot" "snapshot" {
snapshot_id = outscale_snapshot.snapshot.id
data "outscale_snapshot" "snapshot_test" {
snapshot_id = outscale_snapshot.snapshot_01.id
}
`, region)
}

func testAccCheckOutscaleSnapshotDataSourceConfigWithMultipleFilters(region string) string {
creationDate := time.Now().Format("2006-01-02")
return fmt.Sprintf(`
resource "outscale_volume" "external1" {
subregion_name = "%sa"
size = 10
}
resource "outscale_snapshot" "snapshot" {
resource "outscale_snapshot" "snapshot_t2" {
volume_id = outscale_volume.external1.id
}
data "outscale_snapshot" "snapshot" {
snapshot_id = outscale_snapshot.snapshot.id
data "outscale_snapshot" "snapshot_filters" {
snapshot_id = outscale_snapshot.snapshot_t2.id
filter {
name = "volume_sizes"
values = ["10"]
}
filter {
name = "from_creation_date"
values = ["2023"]
values = ["%s"]
}
}
`, region)
`, region, creationDate)
}
12 changes: 6 additions & 6 deletions outscale/resource_outscale_access_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func TestAccOthers_AccessKey_basic(t *testing.T) {
t.Parallel()
resourceName := "outscale_access_key.outscale_access_key"
resourceName := "outscale_access_key.basic_access_key"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -40,7 +40,7 @@ func TestAccOthers_AccessKey_basic(t *testing.T) {

func TestAccOthers_AccessKey_updatedToInactivedKey(t *testing.T) {
t.Parallel()
resourceName := "outscale_access_key.outscale_access_key"
resourceName := "outscale_access_key.update_access_key"

state := "ACTIVE"
stateUpdated := "INACTIVE"
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestAccOthers_AccessKey_updatedToActivedKey(t *testing.T) {
}

func TestAccOthers_AccessKey_updatedExpirationDate(t *testing.T) {
resourceName := "outscale_access_key.outscale_access_key"
resourceName := "outscale_access_key.date_access_key"
expirDate := time.Now().AddDate(1, 1, 0).Format("2006-01-02")
expirDateUpdated := time.Now().AddDate(1, 4, 0).Format("2006-01-02")

Expand Down Expand Up @@ -214,19 +214,19 @@ func testAccCheckOutscaleAccessKeyDestroy(s *terraform.State) error {
}

const testAccOutscaleAccessKeyBasicConfig = `
resource "outscale_access_key" "outscale_access_key" {}`
resource "outscale_access_key" "basic_access_key" {}`

func testAccOutscaleAccessKeyUpdatedConfig(state string) string {
return fmt.Sprintf(`
resource "outscale_access_key" "outscale_access_key" {
resource "outscale_access_key" "update_access_key" {
state = "%s"
}
`, state)
}

func testAccOutscaleAccessKeyExpirationDateConfig(expirDate string) string {
return fmt.Sprintf(`
resource "outscale_access_key" "outscale_access_key" {
resource "outscale_access_key" "date_access_key" {
expiration_date = "%s"
}
`, expirDate)
Expand Down
2 changes: 1 addition & 1 deletion outscale/resource_outscale_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func ResourceOutscaleSnapshotCreate(d *schema.ResourceData, meta interface{}) er
log.Printf("Waiting for Snapshot %s to become available...", resp.Snapshot.GetSnapshotId())

stateConf := &resource.StateChangeConf{
Pending: []string{"pending", "pending/queued", "queued", "importing"},
Pending: []string{"pending", "in-queue", "queued", "importing"},
Target: []string{"completed"},
Refresh: SnapshotOAPIStateRefreshFunc(conn, resp.Snapshot.GetSnapshotId()),
Timeout: OutscaleImageRetryTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@
"attributes": {
"api_access_rule_id": "##id-0##",
"ca_ids": [
"##id-1##",
"##id-2##"
"##id-2##",
"##id-1##"
],
"cns": [
"outscale-1",
Expand Down Expand Up @@ -193,10 +193,10 @@
"schema_version": 0,
"attributes": {
"ca_fingerprint": "########",
"ca_id": "##id-1##",
"ca_id": "##id-2##",
"ca_pem": "########",
"description": "",
"id": "##id-1##",
"id": "##id-2##",
"request_id": "########"
},
"sensitive_attributes": [],
Expand All @@ -214,10 +214,10 @@
"schema_version": 0,
"attributes": {
"ca_fingerprint": "########",
"ca_id": "##id-2##",
"ca_id": "##id-1##",
"ca_pem": "########",
"description": "",
"id": "##id-2##",
"id": "##id-1##",
"request_id": "########"
},
"sensitive_attributes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
"attributes": {
"api_access_rule_id": "##id-3##",
"ca_ids": [
"##id-2##",
"##id-1##"
"##id-1##",
"##id-2##"
],
"cns": [
"outscale-1",
Expand Down Expand Up @@ -265,8 +265,8 @@
"attributes": {
"api_access_rule_id": "##id-0##",
"ca_ids": [
"##id-2##",
"##id-1##"
"##id-1##",
"##id-2##"
],
"cns": [
"outscale-1",
Expand Down Expand Up @@ -296,10 +296,10 @@
"schema_version": 0,
"attributes": {
"ca_fingerprint": "########",
"ca_id": "##id-2##",
"ca_id": "##id-1##",
"ca_pem": "########",
"description": "",
"id": "##id-2##",
"id": "##id-1##",
"request_id": "########"
},
"sensitive_attributes": [],
Expand All @@ -317,10 +317,10 @@
"schema_version": 0,
"attributes": {
"ca_fingerprint": "########",
"ca_id": "##id-1##",
"ca_id": "##id-2##",
"ca_pem": "########",
"description": "",
"id": "##id-1##",
"id": "##id-2##",
"request_id": "########"
},
"sensitive_attributes": [],
Expand Down
Loading

0 comments on commit 1ca482d

Please sign in to comment.