Skip to content

Commit

Permalink
Add test for datasource consul_service_health
Browse files Browse the repository at this point in the history
  • Loading branch information
Rémi Lapeyre committed Mar 19, 2019
1 parent 3b8ca3f commit 181c4a4
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions consul/data_source_consul_service_health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@ func TestAccDataConsulServiceHealth(t *testing.T) {
})
}

func TestAccDataConsulServiceHealthPassing(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccDataConsulServiceHealthPassingSetup,
Check: resource.ComposeTestCheckFunc(),
},
resource.TestStep{
Config: testAccDataConsulServiceHealthPassingFalse,
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSourceValue("data.consul_service_health.google", "name", "google"),
testAccCheckDataSourceValue("data.consul_service_health.google", "passing", "false"),
testAccCheckDataSourceValue("data.consul_service_health.google", "results.#", "2"),
),
},
resource.TestStep{
Config: testAccDataConsulServiceHealthPassingTrue,
Check: resource.ComposeTestCheckFunc(
testAccCheckDataSourceValue("data.consul_service_health.google", "name", "google"),
testAccCheckDataSourceValue("data.consul_service_health.google", "passing", "true"),
testAccCheckDataSourceValue("data.consul_service_health.google", "results.#", "1"),
),
},
},
})
}

const testAccDataConsulServiceHealth = `
data "consul_service_health" "consul" {
name = "consul"
Expand All @@ -66,3 +95,84 @@ data "consul_service_health" "consul" {
}
}
`

const testAccDataConsulServiceHealthPassingSetup = `
resource "consul_node" "compute1" {
name = "compute-google1"
address = "www.google.com"
}
resource "consul_service" "google1" {
name = "google"
node = "${consul_node.compute1.name}"
port = 80
tags = ["tag0"]
check {
check_id = "service:redis1"
name = "Redis health check"
status = "passing"
http = "https://www.hashicorptest.com"
tls_skip_verify = false
method = "PUT"
interval = "5s"
timeout = "1s"
deregister_critical_service_after = "30s"
header {
name = "foo"
value = ["test"]
}
header {
name = "bar"
value = ["test"]
}
}
}
resource "consul_node" "compute2" {
name = "compute-google2"
address = "www.google.com"
}
resource "consul_service" "google2" {
name = "google"
node = "${consul_node.compute2.name}"
port = 80
tags = ["tag0"]
check {
check_id = "service:redis1"
name = "Redis health check"
status = "critical"
http = "https://www.hashicorptest.com"
tls_skip_verify = false
method = "PUT"
interval = "5s"
timeout = "1s"
deregister_critical_service_after = "30s"
header {
name = "foo"
value = ["test"]
}
header {
name = "bar"
value = ["test"]
}
}
}`

const testAccDataConsulServiceHealthPassingFalse = testAccDataConsulServiceHealthPassingSetup + `
data "consul_service_health" "google" {
name = "google"
passing = "false"
}
`
const testAccDataConsulServiceHealthPassingTrue = testAccDataConsulServiceHealthPassingSetup + `
data "consul_service_health" "google" {
name = "google"
}
`

0 comments on commit 181c4a4

Please sign in to comment.