Skip to content

Commit

Permalink
test update
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm committed Sep 22, 2023
1 parent faa82b9 commit cc1bd61
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 24 deletions.
7 changes: 7 additions & 0 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ var Pi_capture_storage_image_path string
var Pi_capture_cloud_storage_access_key string
var Pi_capture_cloud_storage_secret_key string

var ISDelegegatedVPC string

// For Image

var IsImageName string
Expand Down Expand Up @@ -1042,6 +1044,11 @@ func init() {
fmt.Println("[WARN] Set the environment variable IMAGE_COS_URL with a VALID COS Image SQL URL for testing ibm_is_image resources on staging/test")
}

ISDelegegatedVPC = os.Getenv("IS_DELEGATED_VPC")
if ISDelegegatedVPC == "" {
ISDelegegatedVPC = "tfp-test-vpc-hub-false-del"
fmt.Println("[WARN] Set the environment variable IS_DELEGATED_VPC with a VALID created vpc name for testing ibm_is_vpc data source on staging/test")
}
// Added for resource image testing
Image_cos_url_encrypted = os.Getenv("IMAGE_COS_URL_ENCRYPTED")
if Image_cos_url_encrypted == "" {
Expand Down
141 changes: 117 additions & 24 deletions ibm/service/vpc/data_source_ibm_is_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,17 +831,20 @@ func dataSourceIBMIsVPCVpcdnsToMap(model *vpcv1.Vpcdns) (map[string]interface{},
if err != nil {
return modelMap, err
}
modelMap["resolver"] = []map[string]interface{}{resolverMap}
// modelMap["resolver"] = []map[string]interface{}{resolverMap}
log.Printf("[INFO] UJJK map is %v", []map[string]interface{}{resolverMap})
log.Printf("[INFO] UJJK map is %+v", []map[string]interface{}{resolverMap})
log.Printf("[INFO] UJJK map is %#v", []map[string]interface{}{resolverMap})
return modelMap, nil
}

func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[string]interface{}, error) {
if _, ok := model.(*vpcv1.VpcdnsResolverTypeDelegated); ok {
return dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model.(*vpcv1.VpcdnsResolverTypeDelegated))
} else if _, ok := model.(*vpcv1.VpcdnsResolverTypeManual); ok {
return resourceIBMIsVPCVpcdnsResolverTypeManualToMap(model.(*vpcv1.VpcdnsResolverTypeManual), "", "")
return dataSourceIBMIsVPCVpcdnsResolverTypeManualToMap(model.(*vpcv1.VpcdnsResolverTypeManual))
} else if _, ok := model.(*vpcv1.VpcdnsResolverTypeSystem); ok {
return resourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model.(*vpcv1.VpcdnsResolverTypeSystem), "", "")
return dataSourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model.(*vpcv1.VpcdnsResolverTypeSystem))
} else if _, ok := model.(*vpcv1.VpcdnsResolver); ok {
modelMap := make(map[string]interface{})
model := model.(*vpcv1.VpcdnsResolver)
Expand All @@ -856,18 +859,11 @@ func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[
modelMap["servers"] = servers
modelMap["type"] = model.Type
if model.VPC != nil {
modelMap["vpc_id"] = *model.VPC.ID
modelMap["vpc_crn"] = *model.VPC.CRN
modelMap["vpc_name"] = *model.VPC.Name
if model.VPC.Remote != nil {
if model.VPC.Remote.Account != nil {
modelMap["vpc_remote_account_id"] = *model.VPC.Remote.Account.ID
}
if model.VPC.Remote.Region != nil {
modelMap["vpc_remote_region"] = *model.VPC.Remote.Region.Name
}
vpcMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model.VPC)
if err != nil {
return modelMap, err
}

modelMap["vpc"] = []map[string]interface{}{vpcMap}
}

if model.ManualServers != nil {
Expand All @@ -890,6 +886,30 @@ func dataSourceIBMIsVPCVpcdnsResolverToMap(model vpcv1.VpcdnsResolverIntf) (map[
}
}

func dataSourceIBMIsVPCVpcdnsResolverTypeManualToMap(model *vpcv1.VpcdnsResolverTypeManual) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
servers := []map[string]interface{}{}
for _, serversItem := range model.Servers {
serversItemMap, err := resourceIBMIsVPCDnsServerToMap(&serversItem)
if err != nil {
return modelMap, err
}
servers = append(servers, serversItemMap)
}
modelMap["servers"] = servers
manualServers := []map[string]interface{}{}
for _, manualServersItem := range model.ManualServers {
manualServersItemMap, err := resourceIBMIsVPCDnsServerToMap(&manualServersItem)
if err != nil {
return modelMap, err
}
manualServers = append(manualServers, manualServersItemMap)
}
modelMap["manual_servers"] = manualServers
modelMap["type"] = model.Type
return modelMap, nil
}

func dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model *vpcv1.VpcdnsResolverTypeDelegated) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
servers := []map[string]interface{}{}
Expand All @@ -903,17 +923,11 @@ func dataSourceIBMIsVPCVpcdnsResolverTypeDelegatedToMap(model *vpcv1.VpcdnsResol
modelMap["servers"] = servers
modelMap["type"] = model.Type
if model.VPC != nil {
modelMap["vpc_id"] = *model.VPC.ID
modelMap["vpc_crn"] = *model.VPC.CRN
modelMap["vpc_name"] = *model.VPC.Name
if model.VPC.Remote != nil {
if model.VPC.Remote.Account != nil {
modelMap["vpc_remote_account_id"] = *model.VPC.Remote.Account.ID
}
if model.VPC.Remote.Region != nil {
modelMap["vpc_remote_region"] = *model.VPC.Remote.Region.Name
}
vpcMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model.VPC)
if err != nil {
return modelMap, err
}
modelMap["vpc"] = []map[string]interface{}{vpcMap}
}
return modelMap, nil
}
Expand All @@ -926,3 +940,82 @@ func dataSourceIBMIsVPCVPCHealthReasonToMap(model *vpcv1.VPCHealthReason) (map[s
}
return modelMap, nil
}

func dataSourceIBMIsVPCVpcdnsResolverTypeSystemToMap(model *vpcv1.VpcdnsResolverTypeSystem) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
servers := []map[string]interface{}{}
for _, serversItem := range model.Servers {
serversItemMap, err := resourceIBMIsVPCDnsServerToMap(&serversItem)
if err != nil {
return modelMap, err
}
servers = append(servers, serversItemMap)
}
modelMap["servers"] = servers
modelMap["configuration"] = model.Configuration
modelMap["type"] = model.Type
return modelMap, nil
}

func dataSourceIBMIsVPCVPCReferenceDnsResolverContextToMap(model *vpcv1.VPCReferenceDnsResolverContext) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["crn"] = model.CRN
if model.Deleted != nil {
deletedMap, err := dataSourceIBMIsVPCVPCReferenceDnsResolverContextDeletedToMap(model.Deleted)
if err != nil {
return modelMap, err
}
modelMap["deleted"] = []map[string]interface{}{deletedMap}
}
modelMap["href"] = model.Href
modelMap["id"] = model.ID
modelMap["name"] = model.Name
if model.Remote != nil {
remoteMap, err := dataSourceIBMIsVPCVPCRemoteToMap(model.Remote)
if err != nil {
return modelMap, err
}
modelMap["remote"] = []map[string]interface{}{remoteMap}
}
modelMap["resource_type"] = model.ResourceType
return modelMap, nil
}

func dataSourceIBMIsVPCVPCReferenceDnsResolverContextDeletedToMap(model *vpcv1.VPCReferenceDnsResolverContextDeleted) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["more_info"] = model.MoreInfo
return modelMap, nil
}

func dataSourceIBMIsVPCVPCRemoteToMap(model *vpcv1.VPCRemote) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
if model.Account != nil {
accountMap, err := dataSourceIBMIsVPCAccountReferenceToMap(model.Account)
if err != nil {
return modelMap, err
}
modelMap["account"] = []map[string]interface{}{accountMap}
}
if model.Region != nil {
regionMap, err := dataSourceIBMIsVPCRegionReferenceToMap(model.Region)
if err != nil {
return modelMap, err
}
modelMap["region"] = []map[string]interface{}{regionMap}
}
return modelMap, nil
}

func dataSourceIBMIsVPCAccountReferenceToMap(model *vpcv1.AccountReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["id"] = model.ID
modelMap["resource_type"] = model.ResourceType
return modelMap, nil
}

func dataSourceIBMIsVPCRegionReferenceToMap(model *vpcv1.RegionReference) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["href"] = model.Href
modelMap["name"] = model.Name
return modelMap, nil
}
47 changes: 47 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,44 @@ func TestAccIBMISVPCDatasource_basic(t *testing.T) {
},
})
}
func TestAccIBMISVPCDatasource_dns(t *testing.T) {
var vpc string
name := acc.ISDelegegatedVPC

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
CheckDestroy: testAccCheckIBMISVPCDestroy,
Steps: []resource.TestStep{
{
Config: testDSCheckIBMISVPCDnsConfig(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckIBMISVPCExists("ibm_is_vpc.testacc_vpc", vpc),
resource.TestCheckResourceAttr(
"data.ibm_is_vpc.ds_vpc", "name", name),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "cse_source_addresses.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_network_acl_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_security_group_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_routing_table_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "cse_source_addresses.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_network_acl_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_security_group_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "default_routing_table_name"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.enable_hub"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolution_binding_count"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.servers.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.crn"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.id"),
resource.TestCheckResourceAttrSet("data.ibm_is_vpc.ds_vpc", "dns.0.resolver.0.vpc.0.resource_type"),
),
},
},
})
}

func TestAccIBMISVPCDatasource_securityGroup(t *testing.T) {
var vpc string
Expand Down Expand Up @@ -81,6 +119,15 @@ func testDSCheckIBMISVPCConfig(name string) string {
identifier = "${ibm_is_vpc.testacc_vpc.id}"
}`, name)
}
func testDSCheckIBMISVPCDnsConfig(name string) string {
return fmt.Sprintf(`
resource "ibm_is_vpc" "testacc_vpc" {
name = "for-test"
}
data "ibm_is_vpc" "ds_vpc" {
name = "%s"
}`, name)
}

func testDSCheckIBMISVPCSgConfig(vpcname, sgname string) string {
return fmt.Sprintf(`
Expand Down

0 comments on commit cc1bd61

Please sign in to comment.