Skip to content

Commit

Permalink
Self review
Browse files Browse the repository at this point in the history
Signed-off-by: Dainius Serplis <[email protected]>
  • Loading branch information
Didainius committed Sep 30, 2023
1 parent 9f335a7 commit 5aa5ae0
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 153 deletions.
27 changes: 10 additions & 17 deletions vcd/datasource_vcd_network_isolated_v2_nsxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,14 @@ func TestAccVcdNetworkIsolatedV2NsxtDS(t *testing.T) {

// String map to fill the template
var params = StringMap{
"Org": testConfig.VCD.Org,
"NsxtVdc": testConfig.Nsxt.Vdc,
"NetworkName": t.Name(),
"Tags": "network nsxt",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
"TestName": t.Name(),
"NsxtManager": testConfig.Nsxt.Manager,
"IpDiscoveryProfileName": testConfig.Nsxt.IpDiscoveryProfile,
"MacDiscoveryProfileName": testConfig.Nsxt.MacDiscoveryProfile,
"QosProfileName": testConfig.Nsxt.QosProfile,
"SpoofGuardProfileName": testConfig.Nsxt.SpoofGuardProfile,
"SegmentSecurityProfileName": testConfig.Nsxt.SegmentSecurityProfile,
"Org": testConfig.VCD.Org,
"NsxtVdc": testConfig.Nsxt.Vdc,
"NetworkName": t.Name(),
"Tags": "network nsxt",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
}
testParamsNotEmpty(t, params)

Expand Down Expand Up @@ -66,7 +59,7 @@ func TestAccVcdNetworkIsolatedV2NsxtDS(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_network_isolated_v2.net1", "id"),
// Ensure that all fields are the same except field count '%' (because datasource has `filter` field)
resourceFieldsEqual("vcd_network_isolated_v2.net1", "data.vcd_network_isolated_v2.ds", []string{"%", "segment_profile_template_id"}),
resourceFieldsEqual("vcd_network_isolated_v2.net1", "data.vcd_network_isolated_v2.ds", []string{"%"}),
),
},
{
Expand All @@ -82,7 +75,7 @@ func TestAccVcdNetworkIsolatedV2NsxtDS(t *testing.T) {
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_network_isolated_v2.net1", "id"),
// Ensure that all fields are the same except field count '%' (because datasource has `filter` field)
resourceFieldsEqual("vcd_network_isolated_v2.net1", "data.vcd_network_isolated_v2.ds", []string{"%", "segment_profile_template_id"}),
resourceFieldsEqual("vcd_network_isolated_v2.net1", "data.vcd_network_isolated_v2.ds", []string{"%"}),
),
},
},
Expand Down
42 changes: 14 additions & 28 deletions vcd/datasource_vcd_network_routed_v2_nsxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,14 @@ func TestAccVcdNetworkRoutedV2NsxtDS(t *testing.T) {

// String map to fill the template
var params = StringMap{
"Org": testConfig.VCD.Org,
"NsxtVdc": testConfig.Nsxt.Vdc,
"EdgeGw": testConfig.Nsxt.EdgeGateway,
"NetworkName": t.Name(),
"Tags": "network nsxt",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
"TestName": t.Name(),
"NsxtManager": testConfig.Nsxt.Manager,
"IpDiscoveryProfileName": testConfig.Nsxt.IpDiscoveryProfile,
"MacDiscoveryProfileName": testConfig.Nsxt.MacDiscoveryProfile,
"QosProfileName": testConfig.Nsxt.QosProfile,
"SpoofGuardProfileName": testConfig.Nsxt.SpoofGuardProfile,
"SegmentSecurityProfileName": testConfig.Nsxt.SegmentSecurityProfile,
"Org": testConfig.VCD.Org,
"EdgeGw": testConfig.Nsxt.EdgeGateway,
"NetworkName": t.Name(),
"Tags": "network nsxt",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
}
testParamsNotEmpty(t, params)

Expand Down Expand Up @@ -66,30 +58,24 @@ func TestAccVcdNetworkRoutedV2NsxtDS(t *testing.T) {
Config: configText2,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_network_routed_v2.net1", "id"),
// Ensure that all fields are the same except field count '%' (because
// datasource has `filter` field) and `segment_profile_template_id` that cannot
// be read
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%", "segment_profile_template_id"}),
// Ensure that all fields are the same except field count '%' (because datasource has `filter` field)
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%"}),
),
},
{
Config: configText3,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_network_routed_v2.net1", "id"),
// Ensure that all fields are the same except field count '%' (because
// datasource has `filter` field) and `segment_profile_template_id` that cannot
// be read
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%", "segment_profile_template_id"}),
// Ensure that all fields are the same except field count '%' (because datasource has `filter` field)
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%"}),
),
},
{
Config: configText4,
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("vcd_network_routed_v2.net1", "id"),
// Ensure that all fields are the same except field count '%' (because
// datasource has `filter` field) and `segment_profile_template_id` that cannot
// be read
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%", "segment_profile_template_id"}),
// Ensure that all fields are the same except field count '%' (because datasource has `filter` field)
resourceFieldsEqual("vcd_network_routed_v2.net1", "data.vcd_network_routed_v2.ds", []string{"%"}),
),
},
},
Expand Down
44 changes: 16 additions & 28 deletions vcd/resource_vcd_network_routed_v2_nsxt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,15 @@ func TestAccVcdNetworkRoutedV2Nsxt(t *testing.T) {

// String map to fill the template
var params = StringMap{
"Org": testConfig.VCD.Org,
"NsxtVdc": testConfig.Nsxt.Vdc,
"EdgeGw": testConfig.Nsxt.EdgeGateway,
"NetworkName": t.Name(),
"Tags": "network",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
"TestName": t.Name(),
"NsxtManager": testConfig.Nsxt.Manager,
"IpDiscoveryProfileName": testConfig.Nsxt.IpDiscoveryProfile,
"MacDiscoveryProfileName": testConfig.Nsxt.MacDiscoveryProfile,
"QosProfileName": testConfig.Nsxt.QosProfile,
"SpoofGuardProfileName": testConfig.Nsxt.SpoofGuardProfile,
"SegmentSecurityProfileName": testConfig.Nsxt.SegmentSecurityProfile,
"Org": testConfig.VCD.Org,
"NsxtVdc": testConfig.Nsxt.Vdc,
"EdgeGw": testConfig.Nsxt.EdgeGateway,
"NetworkName": t.Name(),
"Tags": "network",
"MetadataKey": "key1",
"MetadataValue": "value1",
"MetadataKeyUpdated": "key2",
"MetadataValueUpdated": "value2",
}
testParamsNotEmpty(t, params)

Expand Down Expand Up @@ -110,11 +103,10 @@ func TestAccVcdNetworkRoutedV2Nsxt(t *testing.T) {

// Check that import works
{ // step 3
ResourceName: "vcd_network_routed_v2.net1",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: importStateIdOrgNsxtVdcObject(t.Name()),
ImportStateVerifyIgnore: []string{"segment_profile_template_id"},
ResourceName: "vcd_network_routed_v2.net1",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: importStateIdOrgNsxtVdcObject(t.Name()),
},

{ // step 4
Expand All @@ -136,7 +128,7 @@ func TestAccVcdNetworkRoutedV2Nsxt(t *testing.T) {
postTestChecks(t)
}

const TestAccVcdNetworkRoutedV2NsxtStep1 = testAccVcdNsxtSegmentProfileTemplate + `
const TestAccVcdNetworkRoutedV2NsxtStep1 = `
data "vcd_nsxt_edgegateway" "existing" {
org = "{{.Org}}"
name = "{{.EdgeGw}}"
Expand All @@ -160,12 +152,10 @@ resource "vcd_network_routed_v2" "net1" {
metadata = {
{{.MetadataKey}} = "{{.MetadataValue}}"
}
segment_profile_template_id = vcd_nsxt_segment_profile_template.complete.id
}
`

const TestAccVcdNetworkRoutedV2NsxtStep2 = testAccVcdNsxtSegmentProfileTemplate + `
const TestAccVcdNetworkRoutedV2NsxtStep2 = `
data "vcd_nsxt_edgegateway" "existing" {
org = "{{.Org}}"
name = "{{.EdgeGw}}"
Expand Down Expand Up @@ -202,7 +192,7 @@ resource "vcd_network_routed_v2" "net1" {
}
`

const TestAccVcdNetworkRoutedV2NsxtStep3 = testAccVcdNsxtSegmentProfileTemplate + `
const TestAccVcdNetworkRoutedV2NsxtStep3 = `
data "vcd_nsxt_edgegateway" "existing" {
org = "{{.Org}}"
name = "{{.EdgeGw}}"
Expand All @@ -217,8 +207,6 @@ resource "vcd_network_routed_v2" "net1" {
gateway = "1.1.1.1"
prefix_length = 24
segment_profile_template_id = vcd_nsxt_segment_profile_template.complete.id
}
`

Expand Down
8 changes: 0 additions & 8 deletions vcd/resource_vcd_nsxt_network_imported.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,6 @@ func resourceVcdNsxtNetworkImported() *schema.Resource {
Optional: true,
Description: "DNS suffix",
},
// Segment Profile Template cannot be retrieved using `GET` endpoints. Only supports
// POST/PUT
"segment_profile_template_id": {
Type: schema.TypeString,
Optional: true,
Description: "Segment Profile Template ID",
},
},
}
}
Expand Down Expand Up @@ -456,7 +449,6 @@ func getOpenApiOrgVdcImportedNetworkType(d *schema.ResourceData, vcdClient *VCDC
if err != nil {
return nil, err
}
getOpenApiOrgVdcNetworkSegmentProfileTemplateSetting(d, orgVdcNetworkConfig)

return orgVdcNetworkConfig, nil
}
7 changes: 2 additions & 5 deletions vcd/resource_vcd_nsxt_network_imported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestAccVcdNsxtNetworkImportedNsxtLogicalSwitch(t *testing.T) {
"end_address": "1.1.1.20",
}),
resource.TestCheckResourceAttrSet("vcd_nsxt_network_imported.net1", "owner_id"),
resource.TestCheckResourceAttrSet("vcd_network_isolated_v2.net1", "segment_profile_template_id"),
),
},
{ // step 2
Expand Down Expand Up @@ -99,7 +98,7 @@ func TestAccVcdNsxtNetworkImportedNsxtLogicalSwitch(t *testing.T) {
postTestChecks(t)
}

const testAccVcdNetworkImportedV2NsxtStep1 = testAccVcdNsxtSegmentProfileTemplate + `
const testAccVcdNetworkImportedV2NsxtStep1 = `
resource "vcd_nsxt_network_imported" "net1" {
org = "{{.Org}}"
vdc = "{{.NsxtVdc}}"
Expand All @@ -115,12 +114,10 @@ resource "vcd_nsxt_network_imported" "net1" {
start_address = "1.1.1.10"
end_address = "1.1.1.20"
}
segment_profile_template_id = vcd_nsxt_segment_profile_template.complete.id
}
`

const TestAccVcdNetworkImportedV2NsxtStep2 = testAccVcdNsxtSegmentProfileTemplate + `
const TestAccVcdNetworkImportedV2NsxtStep2 = `
resource "vcd_nsxt_network_imported" "net1" {
org = "{{.Org}}"
vdc = "{{.NsxtVdc}}"
Expand Down
69 changes: 2 additions & 67 deletions vcd/resource_vcd_nsxt_network_segment_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,50 +37,17 @@ func TestAccVcdNsxtNetworkSegmentProfileCustom(t *testing.T) {
configText2DS := templateFill(testAccVcdNsxtNetworkSegmentProfileCustomDS, params)
debugPrintf("#[DEBUG] CONFIGURATION for step 2: %s", configText2DS)

// params["FuncName"] = t.Name() + "step3"
// configText3 := templateFill(testAccVcdNsxtNetworkSegmentProfileGlobalDefault, params)
// debugPrintf("#[DEBUG] CONFIGURATION for step 3: %s", configText3)

// params["FuncName"] = t.Name() + "step4"
// configText4DS := templateFill(testAccVcdNsxtNetworkSegmentProfileGlobalDefaultDS, params)
// debugPrintf("#[DEBUG] CONFIGURATION for step 4: %s", configText4DS)

if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
}

resource.Test(t, resource.TestCase{
ProviderFactories: testAccProviders,
// CheckDestroy: testAccCheckVcdSegmentProfileTemplateDestroy("vcd_nsxt_alb_controller.first"),
Steps: []resource.TestStep{
{
Config: configText1,
Check: resource.ComposeAggregateTestCheckFunc(
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.first", "id", regexp.MustCompile(`\d*`)),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "name", t.Name()+"-empty"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "description", "description"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "ip_discovery_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "mac_discovery_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "spoof_guard_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "qos_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "segment_security_profile_id", ""),

// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.complete", "name", t.Name()+"-complete"),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "ip_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "mac_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "spoof_guard_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "qos_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "segment_security_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),

// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "name", t.Name()+"-half-complete"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "description", ""),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "ip_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "mac_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "spoof_guard_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "qos_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "segment_security_profile_id", ""),
),
Check: resource.ComposeAggregateTestCheckFunc(),
},

{
Expand Down Expand Up @@ -200,14 +167,6 @@ func TestAccVcdNsxtNetworkSegmentProfileTemplate(t *testing.T) {
configText2DS := templateFill(testAccVcdNsxtNetworkSegmentProfileTemplateDS, params)
debugPrintf("#[DEBUG] CONFIGURATION for step 2: %s", configText2DS)

// params["FuncName"] = t.Name() + "step3"
// configText3 := templateFill(testAccVcdNsxtNetworkSegmentProfileGlobalDefault, params)
// debugPrintf("#[DEBUG] CONFIGURATION for step 3: %s", configText3)

// params["FuncName"] = t.Name() + "step4"
// configText4DS := templateFill(testAccVcdNsxtNetworkSegmentProfileGlobalDefaultDS, params)
// debugPrintf("#[DEBUG] CONFIGURATION for step 4: %s", configText4DS)

if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
return
Expand All @@ -219,31 +178,7 @@ func TestAccVcdNsxtNetworkSegmentProfileTemplate(t *testing.T) {
Steps: []resource.TestStep{
{
Config: configText1,
Check: resource.ComposeAggregateTestCheckFunc(
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.first", "id", regexp.MustCompile(`\d*`)),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "name", t.Name()+"-empty"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "description", "description"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "ip_discovery_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "mac_discovery_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "spoof_guard_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "qos_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.empty", "segment_security_profile_id", ""),

// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.complete", "name", t.Name()+"-complete"),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "ip_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "mac_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "spoof_guard_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "qos_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.complete", "segment_security_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),

// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "name", t.Name()+"-half-complete"),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "description", ""),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "ip_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "mac_discovery_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestMatchResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "spoof_guard_profile_id", regexp.MustCompile(`[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$`)),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "qos_profile_id", ""),
// resource.TestCheckResourceAttr("vcd_nsxt_segment_profile_template.half-complete", "segment_security_profile_id", ""),
),
Check: resource.ComposeAggregateTestCheckFunc(),
},

{
Expand Down

0 comments on commit 5aa5ae0

Please sign in to comment.