Skip to content

Commit

Permalink
Added new data source test
Browse files Browse the repository at this point in the history
Added the load balancer test
Added the network test

Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Jul 3, 2020
1 parent 2601717 commit 439c0d4
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
64 changes: 64 additions & 0 deletions civo/datasource_loadbalancer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package civo

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceCivoLoadBalancer_basic(t *testing.T) {
datasourceName := "data.civo_loadbalancer.foobar"
name := acctest.RandomWithPrefix("lb-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCivoLoadBalancerConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "hostname", name),
resource.TestCheckResourceAttr(datasourceName, "protocol", "http"),
resource.TestCheckResourceAttr(datasourceName, "port", "80"),
resource.TestCheckResourceAttr(datasourceName, "max_request_size", "30"),
resource.TestCheckResourceAttr(datasourceName, "policy", "round_robin"),
resource.TestCheckResourceAttr(datasourceName, "health_check_path", "/"),
resource.TestCheckResourceAttr(datasourceName, "max_conns", "10"),
resource.TestCheckResourceAttr(datasourceName, "backend.#", "1"),
),
},
},
})
}

func testAccDataSourceCivoLoadBalancerConfig(name string) string {
return fmt.Sprintf(`
resource "civo_instance" "vm" {
hostname = "instance-%s"
}
resource "civo_loadbalancer" "foobar" {
hostname = "%s"
protocol = "http"
port = 80
max_request_size = 30
policy = "round_robin"
health_check_path = "/"
max_conns = 10
fail_timeout = 40
depends_on = [civo_instance.vm]
backend {
instance_id = civo_instance.vm.id
protocol = "http"
port = 80
}
}
data "civo_loadbalancer" "foobar" {
hostname = civo_loadbalancer.foobar.hostname
}
`, name, name)
}
39 changes: 39 additions & 0 deletions civo/datasource_network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package civo

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

func TestAccDataSourceCivoNetwork_basic(t *testing.T) {
datasourceName := "data.civo_network.foobar"
name := acctest.RandomWithPrefix("net-test")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCivoNetworkConfig(name),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(datasourceName, "label", name),
),
},
},
})
}

func testAccDataSourceCivoNetworkConfig(name string) string {
return fmt.Sprintf(`
resource "civo_network" "foobar" {
label = "%s"
}
data "civo_network" "foobar" {
label = civo_network.foobar.name
}
`, name)
}

0 comments on commit 439c0d4

Please sign in to comment.