Skip to content

Commit

Permalink
Merge pull request IBM-Cloud#5 from sumit-tembe-ibm/swift
Browse files Browse the repository at this point in the history
added testcases object storage account
  • Loading branch information
sagarkale1 authored Feb 26, 2018
2 parents 99f410f + b7d50c2 commit 13c834d
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions ibm/resource_ibm_object_storage_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package ibm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
"github.com/softlayer/softlayer-go/services"
"strconv"
"testing"
)

//Testcase for SWIFT object storage account
func TestAccIBMObjectStorageAccount_Basic(t *testing.T) {
var accountName string

Expand All @@ -26,7 +27,25 @@ func TestAccIBMObjectStorageAccount_Basic(t *testing.T) {
},
})
}
//Testcase for S3 object storage account
func TestAccIBMObjectStorageS3Account_Basic(t *testing.T) {
var accountName string

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckIBMObjectStorageAccountDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccCheckIBMObjectStorageS3AccountConfig_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMObjectStorageAccountExists("ibm_object_storage_account.testacc_foobar", &accountName),
testAccCheckIBMObjectStorageAccountAttributes(&accountName),
),
},
},
})
}
func TestAccIBMObjectStorageAccountWithTag(t *testing.T) {
var accountName string

Expand Down Expand Up @@ -58,6 +77,22 @@ func TestAccIBMObjectStorageAccountWithTag(t *testing.T) {
}

func testAccCheckIBMObjectStorageAccountDestroy(s *terraform.State) error {
sess := testAccProvider.Meta().(ClientSession).SoftLayerSession()
storageService := services.GetNetworkStorageService(sess)
for _, rs := range s.RootModule().Resources {
if rs.Type != "ibm_object_storage_account" {
continue
}

storageID, _ := strconv.Atoi(rs.Primary.ID)

// Try to find the key
_, err := storageService.Id(storageID).GetObject()

if err == nil {
return fmt.Errorf("Object Storage Account %d still exists", storageID)
}
}
return nil
}

Expand Down Expand Up @@ -94,6 +129,11 @@ var testAccCheckIBMObjectStorageAccountConfig_basic = `
resource "ibm_object_storage_account" "testacc_foobar" {
}`

var testAccCheckIBMObjectStorageS3AccountConfig_basic = `
resource "ibm_object_storage_account" "testacc_foobar" {
accountType = "S3"
}`

var testAccCheckIBMObjectStorageAccountWithTag = `
resource "ibm_object_storage_account" "testacc_foobar" {
tags = ["one", "two"]
Expand Down

0 comments on commit 13c834d

Please sign in to comment.