Skip to content

Commit 7db005f

Browse files
committed
Working acceptance tests for console history and CPE datasources
1 parent fa15399 commit 7db005f

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

data_source_obmcs_core_console_history_data_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ type CoreConsoleHistoryDataDatasourceTestSuite struct {
2525
}
2626

2727
func (s *CoreConsoleHistoryDataDatasourceTestSuite) SetupTest() {
28+
if IsAccTest() {
29+
s.T().Skip()
30+
}
2831
s.Client = GetTestProvider()
2932
s.Provider = Provider(func(d *schema.ResourceData) (interface{}, error) {
3033
return s.Client, nil

data_source_obmcs_core_cpe_test.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,15 @@ func (s *DatasourceCoreCpeTestSuite) SetupTest() {
3333
"baremetal": s.Provider,
3434
}
3535
s.Config = `
36-
data "baremetal_core_cpes" "s" {
37-
compartment_id = "${var.compartment_id}"
38-
}
36+
resource "baremetal_core_cpe" "t" {
37+
compartment_id = "${var.compartment_id}"
38+
display_name = "name1"
39+
ip_address = "142.10.10.2"
40+
}
41+
42+
data "baremetal_core_cpes" "s" {
43+
compartment_id = "${baremetal_core_cpe.t.compartment_id}"
44+
}
3945
`
4046
s.Config += testProviderConfig()
4147
s.ResourceName = "data.baremetal_core_cpes.s"
@@ -53,15 +59,8 @@ func (s *DatasourceCoreCpeTestSuite) TestCpeList() {
5359
{
5460
ID: "id1",
5561
CompartmentID: "compartmentid",
56-
DisplayName: "name",
57-
IPAddress: "10.10.10.2",
58-
TimeCreated: baremetal.Time{Time: time.Now()},
59-
},
60-
{
61-
ID: "id2",
62-
CompartmentID: "compartmentid",
63-
DisplayName: "name",
64-
IPAddress: "10.10.10.3",
62+
DisplayName: "name1",
63+
IPAddress: "142.10.10.2",
6564
TimeCreated: baremetal.Time{Time: time.Now()},
6665
},
6766
},
@@ -78,12 +77,9 @@ func (s *DatasourceCoreCpeTestSuite) TestCpeList() {
7877
ImportStateVerify: true,
7978
Config: s.Config,
8079
Check: resource.ComposeTestCheckFunc(
81-
resource.TestCheckResourceAttr(s.ResourceName, "compartment_id", "compartmentid"),
82-
resource.TestCheckResourceAttr(s.ResourceName, "cpes.0.ip_address", "10.10.10.2"),
83-
resource.TestCheckResourceAttr(s.ResourceName, "cpes.0.id", "id1"),
84-
resource.TestCheckResourceAttr(s.ResourceName, "cpes.1.ip_address", "10.10.10.3"),
85-
resource.TestCheckResourceAttr(s.ResourceName, "cpes.1.id", "id2"),
86-
resource.TestCheckResourceAttr(s.ResourceName, "cpes.#", "2"),
80+
resource.TestCheckResourceAttr(s.ResourceName, "cpes.0.ip_address", "142.10.10.2"),
81+
resource.TestCheckResourceAttr(s.ResourceName, "cpes.0.display_name", "name1"),
82+
resource.TestCheckResourceAttr(s.ResourceName, "cpes.#", "1"),
8783
),
8884
},
8985
},
@@ -94,6 +90,9 @@ func (s *DatasourceCoreCpeTestSuite) TestCpeList() {
9490
}
9591

9692
func (s *DatasourceCoreCpeTestSuite) TestCpePagedList() {
93+
if IsAccTest() {
94+
s.T().Skip()
95+
}
9796
res := &baremetal.ListCpes{}
9897
res.NextPage = "nextpage"
9998
res.Cpes = []baremetal.Cpe{

provider_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,16 @@ func (r *testClient) AssertCalled(t mock.TestingT, methodName string, arguments
5656
return true
5757
}
5858

59-
func GetTestProvider() mockableClient {
60-
acc, err := strconv.ParseBool(os.Getenv("TF_ACC"))
59+
func IsAccTest() bool {
60+
acc, err := strconv.ParseBool(os.Getenv(resource.TestEnvVar))
61+
if err != nil {
62+
panic("Err testing TF_ACC env var. It should be blank or a boolean value.")
63+
}
64+
return acc
65+
}
6166

62-
if err == nil && acc {
67+
func GetTestProvider() mockableClient {
68+
if IsAccTest() {
6369
r := &schema.Resource{
6470
Schema: schemaMap(),
6571
}

0 commit comments

Comments
 (0)