Skip to content

Commit

Permalink
Added data source snapshot test
Browse files Browse the repository at this point in the history
Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Jul 3, 2020
1 parent efbfce8 commit 12c41ce
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions civo/datasource_snapshot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package civo

import (
"fmt"
"testing"

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

func TestAccDataSourceCivoSnapshots_basic(t *testing.T) {
datasourceName := "data.civo_snapshot.foobar"
name := acctest.RandomWithPrefix("snapshot-test")

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

func testAccDataSourceCivoSnapshotsConfig(name string) string {
return fmt.Sprintf(`
resource "civo_instance" "vm" {
hostname = "instance-%s"
}
resource "civo_snapshot" "foobar" {
name = "%s"
instance_id = civo_instance.vm.id
}
data "civo_snapshot" "foobar" {
name = civo_snapshot.foobar.name
}
`, name, name)
}

0 comments on commit 12c41ce

Please sign in to comment.