Skip to content

Commit

Permalink
Add misc test, more adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Didainius committed Jun 7, 2019
1 parent 34df586 commit c3b1c92
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ website/node_modules
*~
.*.swp
.idea
.vscode
*.iml
*.test
*.iml
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ require (
github.com/vmware/go-vcloud-director/v2 v2.2.0
)

replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20
replace github.com/vmware/go-vcloud-director/v2 => github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/ChrisTrenkamp/goxpath v0.0.0-20170922090931-c385f95c6022/go.mod h1:nuWgzSkT5PnyOd+272uUmV0dnAnAn42Mk7PiQC5VzN4=
github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20 h1:u0AW0XwavNi0qQQJVYFqMbVbunwZje2we5obpWRUFlg=
github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190603073202-811d7fc79f20/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ=
github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118 h1:dgXaMkmp1GIpXHFbYqvpEqFErUE/bh6pdFu33EorvuU=
github.com/Didainius/go-vcloud-director/v2 v2.2.1-0.20190607082001-562a09fad118/go.mod h1:+Hq7ryFfgZqsO6mXH29RQFnpIMSujCOMI57otHoXHhQ=
github.com/Unknwon/com v0.0.0-20151008135407-28b053d5a292/go.mod h1:KYCjqMOeHpNuTOiFQU6WEcTG7poCJrUs0YgyHNtn1no=
github.com/abdullin/seq v0.0.0-20160510034733-d5467c17e7af/go.mod h1:5Jv4cbFiHJMsVxt52+i0Ha45fjshj6wxYr1r19tB9bw=
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
Expand Down
17 changes: 8 additions & 9 deletions vcd/resource_vcd_lb_service_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"strings"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/vmware/go-vcloud-director/v2/types/v56"
)

Expand Down Expand Up @@ -67,21 +66,21 @@ func ResourceVcdLbServiceMonitor() *schema.Resource {
Description: "Number of times the specified monitoring Method must fail sequentially before the server is declared down",
},
"type": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{"http", "https", "tcp", "icmp", "udp"}, false),
Description: "Way in which you want to send the health check request to the server",
Type: schema.TypeString,
Required: true,
// ValidateFunc: validation.StringInSlice([]string{"http", "https", "tcp", "icmp", "udp"}, false),
Description: "Way in which you want to send the health check request to the server",
},
"expected": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Description: "String that the monitor expects to match in the status line of the HTTP or HTTPS response (for example, HTTP/1.1)",
},
"method": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"GET", "OPTIONS", "POST"}, false),
Description: "Method to be used to detect server status",
Type: schema.TypeString,
Optional: true,
// ValidateFunc: validation.StringInSlice([]string{"GET", "OPTIONS", "POST"}, false),
Description: "Method to be used to detect server status",
},
"url": &schema.Schema{
Type: schema.TypeString,
Expand Down
33 changes: 25 additions & 8 deletions vcd/resource_vcd_lb_service_monitor_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build gateway lb lbsm ALL functional
// +build gateway lb lbServiceMonitor ALL functional

package vcd

Expand All @@ -16,8 +16,7 @@ import (
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccVcdLbServiceMonitor_Basic(t *testing.T) {
//var vpnName string = t.Name()
func TestAccVcdLbServiceMonitor(t *testing.T) {

if vcdShortTest {
t.Skip(acceptanceTestsSkipped)
Expand All @@ -32,8 +31,8 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) {
"Interval": 5,
"Timeout": 10,
"MaxRetries": 3,
"Method": "POST",
"Tags": "lb lbsm",
"Method": "ASD",
"Tags": "lb lbServiceMonitor",
}

configText := templateFill(testAccVcdLbServiceMonitor_Basic, params)
Expand All @@ -43,8 +42,6 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) {
configTextStep1 := templateFill(testAccVcdLbServiceMonitor_Basic2, params)
debugPrintf("#[DEBUG] CONFIGURATION for step 1: %s", configTextStep1)



resource.Test(t, resource.TestCase{
Providers: testAccProviders,
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -79,6 +76,13 @@ func TestAccVcdLbServiceMonitor_Basic(t *testing.T) {
resource.TestCheckResourceAttr("vcd_lb_service_monitor.lb-service-monitor", "type", "tcp"),
),
},
// Check that import works
resource.TestStep{
ResourceName: "vcd_lb_service_monitor.service-monitor-import",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: importStateIdByOrgVdcEdge(testConfig, params["ServiceMonitorName"].(string)),
},
},
})
}
Expand All @@ -100,6 +104,20 @@ func testAccCheckVcdLbServiceMonitorDestroy(serviceMonitorName string) resource.
}
}

// importStateIdByOrgVdcEdge constructs an import path (ID in Terraform import terms) in the format of:
// organization.vdc.edge-gateway-nane.import-object-name (i.e. my-org.my-vdc.my-edge-gw.objectName) from TestConfig and
// object state.
func importStateIdByOrgVdcEdge(vcd TestConfig, objectName string) resource.ImportStateIdFunc {
return func(*terraform.State) (string, error) {
importId := testConfig.VCD.Org + "." + testConfig.VCD.Vdc + "." + testConfig.Networking.EdgeGateway + "." + objectName
if testConfig.VCD.Org == "" || testConfig.VCD.Vdc == "" || testConfig.Networking.EdgeGateway == "" || objectName == "" {
return "", fmt.Errorf("missing information to generate import path: %s", importId)
}

return importId, nil
}
}

const testAccVcdLbServiceMonitor_Basic = `
resource "vcd_lb_service_monitor" "lb-service-monitor" {
org = "{{.Org}}"
Expand Down Expand Up @@ -144,4 +162,3 @@ resource "vcd_lb_service_monitor" "lb-service-monitor" {
max_retries = {{.MaxRetries}}
}
`

43 changes: 43 additions & 0 deletions vcd/test-templates/misc3.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Remove the first '#' from the next two lines to enable options for terraform executable
# apply-options -parallelism=1
# destroy-options -parallelism=1

# Edge gateway load balancer configuration
# v2.4.0+

variable "service_monitor_count" {
default = 20
}

resource "vcd_lb_service_monitor" "test" {
count = "${var.service_monitor_count}"

org = "{{.Org}}"
vdc = "{{.Vdc}}"
edge_gateway = "{{.EdgeGateway}}"

name = "test-monitor-${count.index}"
interval = 5
timeout = 5
max_retries = 3
type = "http"
method = "POST"
send = "{\"key\": \"value\"}"
expected = "HTTP/1.1"
receive = "OK"

extension = {
"content-type" = "application/json"
"no-body" = ""
}
}


data "vcd_lb_service_monitor" "ds-lb" {
count = "${var.service_monitor_count}"

org = "{{.Org}}"
vdc = "{{.Vdc}}"
edge_gateway = "{{.EdgeGateway}}"
name = "${vcd_lb_service_monitor.test[count.index].name}"
}

0 comments on commit c3b1c92

Please sign in to comment.