Skip to content

Commit 1bd6769

Browse files
Move common test utils to testutils package (#807)
* Move common test utils to `testutils` package Follow-up to #806 This is the last part before being able to split by provider "section" These are all functions that are widely used in tests and will be shared * Also move the widely-used provider and provider factories
1 parent 72a0e3d commit 1bd6769

File tree

71 files changed

+677
-588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+677
-588
lines changed

provider/data_source_cloud_ips_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,19 @@ import (
77
"strings"
88
"testing"
99

10+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
1213
)
1314

1415
func TestAccDataSourceCloudIPsRead(t *testing.T) {
15-
CheckCloudAPITestsEnabled(t)
16+
testutils.CheckCloudAPITestsEnabled(t)
1617

1718
resource.ParallelTest(t, resource.TestCase{
18-
ProviderFactories: testAccProviderFactories,
19+
ProviderFactories: testutils.ProviderFactories,
1920
Steps: []resource.TestStep{
2021
{
21-
Config: testAccExample(t, "data-sources/grafana_cloud_ips/data-source.tf"),
22+
Config: testutils.TestAccExample(t, "data-sources/grafana_cloud_ips/data-source.tf"),
2223
Check: func(s *terraform.State) error {
2324
rs := s.RootModule().Resources["data.grafana_cloud_ips.test"]
2425

provider/data_source_cloud_organization_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"os"
66
"testing"
77

8+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
910
)
1011

1112
func TestAccDatasourceCloudOrganization_Basic(t *testing.T) {
12-
CheckCloudAPITestsEnabled(t)
13+
testutils.CheckCloudAPITestsEnabled(t)
1314

1415
config := fmt.Sprintf(`
1516
data "grafana_cloud_organization" "test" {
@@ -18,7 +19,7 @@ func TestAccDatasourceCloudOrganization_Basic(t *testing.T) {
1819
`, os.Getenv("GRAFANA_CLOUD_ORG"))
1920

2021
resource.ParallelTest(t, resource.TestCase{
21-
ProviderFactories: testAccProviderFactories,
22+
ProviderFactories: testutils.ProviderFactories,
2223
Steps: []resource.TestStep{
2324
{
2425
Config: config,

provider/data_source_cloud_stack_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"testing"
66

77
gapi "github.com/grafana/grafana-api-golang-client"
8+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
910
)
1011

1112
func TestAccDatasourceCloudStack_Basic(t *testing.T) {
12-
CheckCloudAPITestsEnabled(t)
13+
testutils.CheckCloudAPITestsEnabled(t)
1314

1415
prefix := "tfdatatest"
1516

@@ -19,7 +20,7 @@ func TestAccDatasourceCloudStack_Basic(t *testing.T) {
1920
PreCheck: func() {
2021
testAccDeleteExistingStacks(t, prefix)
2122
},
22-
ProviderFactories: testAccProviderFactories,
23+
ProviderFactories: testutils.ProviderFactories,
2324
CheckDestroy: testAccStackCheckDestroy(&stack),
2425
Steps: []resource.TestStep{
2526
{

provider/data_source_dashboard_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"testing"
88

99
gapi "github.com/grafana/grafana-api-golang-client"
10+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1112
)
1213

1314
func TestAccDatasourceDashboardBasicID(t *testing.T) {
14-
CheckOSSTestsEnabled(t)
15+
testutils.CheckOSSTestsEnabled(t)
1516

1617
var dashboard gapi.Dashboard
1718
checks := []resource.TestCheckFunc{
@@ -40,26 +41,26 @@ func TestAccDatasourceDashboardBasicID(t *testing.T) {
4041
}
4142

4243
resource.ParallelTest(t, resource.TestCase{
43-
ProviderFactories: testAccProviderFactories,
44+
ProviderFactories: testutils.ProviderFactories,
4445
CheckDestroy: testAccDashboardCheckDestroy(&dashboard, 0),
4546
Steps: []resource.TestStep{
4647
{
47-
Config: testAccExample(t, "data-sources/grafana_dashboard/data-source.tf"),
48+
Config: testutils.TestAccExample(t, "data-sources/grafana_dashboard/data-source.tf"),
4849
Check: resource.ComposeTestCheckFunc(checks...),
4950
},
5051
},
5152
})
5253
}
5354

5455
func TestAccDatasourceDashboardBadExactlyOneOf(t *testing.T) {
55-
CheckOSSTestsEnabled(t)
56+
testutils.CheckOSSTestsEnabled(t)
5657

5758
// TODO: Make parallelizable
5859
resource.Test(t, resource.TestCase{
59-
ProviderFactories: testAccProviderFactories,
60+
ProviderFactories: testutils.ProviderFactories,
6061
Steps: []resource.TestStep{
6162
{
62-
Config: testAccExample(t, "data-sources/grafana_dashboard/bad-ExactlyOneOf.tf"),
63+
Config: testutils.TestAccExample(t, "data-sources/grafana_dashboard/bad-ExactlyOneOf.tf"),
6364
ExpectError: regexp.MustCompile(".*only one of.*can be specified.*"),
6465
},
6566
},

provider/data_source_dashboards_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"net/url"
55
"testing"
66

7+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
)
910

1011
func TestAccDataSourceDashboardsAllAndByFolderID(t *testing.T) {
11-
CheckOSSTestsEnabled(t)
12+
testutils.CheckOSSTestsEnabled(t)
1213

1314
params := url.Values{
1415
"limit": {"5000"},
@@ -30,10 +31,10 @@ func TestAccDataSourceDashboardsAllAndByFolderID(t *testing.T) {
3031
}
3132

3233
resource.ParallelTest(t, resource.TestCase{
33-
ProviderFactories: testAccProviderFactories,
34+
ProviderFactories: testutils.ProviderFactories,
3435
Steps: []resource.TestStep{
3536
{
36-
Config: testAccExample(t, "data-sources/grafana_dashboards/data-source.tf"),
37+
Config: testutils.TestAccExample(t, "data-sources/grafana_dashboards/data-source.tf"),
3738
Check: resource.ComposeTestCheckFunc(checks...),
3839
},
3940
},

provider/data_source_data_source_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"testing"
55

66
gapi "github.com/grafana/grafana-api-golang-client"
7+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
)
910

1011
func TestAccDatasourceDatasource(t *testing.T) {
11-
CheckOSSTestsEnabled(t)
12+
testutils.CheckOSSTestsEnabled(t)
1213

1314
var dataSource gapi.DataSource
1415
checks := []resource.TestCheckFunc{
@@ -31,11 +32,11 @@ func TestAccDatasourceDatasource(t *testing.T) {
3132
}
3233

3334
resource.ParallelTest(t, resource.TestCase{
34-
ProviderFactories: testAccProviderFactories,
35+
ProviderFactories: testutils.ProviderFactories,
3536
CheckDestroy: testAccDataSourceCheckDestroy(&dataSource),
3637
Steps: []resource.TestStep{
3738
{
38-
Config: testAccExample(t, "data-sources/grafana_data_source/data-source.tf"),
39+
Config: testutils.TestAccExample(t, "data-sources/grafana_data_source/data-source.tf"),
3940
Check: resource.ComposeTestCheckFunc(checks...),
4041
},
4142
},

provider/data_source_folder_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"testing"
77

88
gapi "github.com/grafana/grafana-api-golang-client"
9+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
)
1112

1213
func TestAccDatasourceFolder(t *testing.T) {
13-
CheckOSSTestsEnabled(t)
14+
testutils.CheckOSSTestsEnabled(t)
1415

1516
var folder gapi.Folder
1617
checks := []resource.TestCheckFunc{
@@ -30,11 +31,11 @@ func TestAccDatasourceFolder(t *testing.T) {
3031
}
3132

3233
resource.ParallelTest(t, resource.TestCase{
33-
ProviderFactories: testAccProviderFactories,
34+
ProviderFactories: testutils.ProviderFactories,
3435
CheckDestroy: testAccFolderCheckDestroy(&folder),
3536
Steps: []resource.TestStep{
3637
{
37-
Config: testAccExample(t, "data-sources/grafana_folder/data-source.tf"),
38+
Config: testutils.TestAccExample(t, "data-sources/grafana_folder/data-source.tf"),
3839
Check: resource.ComposeTestCheckFunc(checks...),
3940
},
4041
},

provider/data_source_folders_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"testing"
55

66
gapi "github.com/grafana/grafana-api-golang-client"
7+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
)
910

1011
func TestAccDatasourceFolders(t *testing.T) {
11-
CheckOSSTestsEnabled(t)
12+
testutils.CheckOSSTestsEnabled(t)
1213

1314
var folderA gapi.Folder
1415
var folderB gapi.Folder
@@ -32,14 +33,14 @@ func TestAccDatasourceFolders(t *testing.T) {
3233

3334
// TODO: Make parallelizable
3435
resource.Test(t, resource.TestCase{
35-
ProviderFactories: testAccProviderFactories,
36+
ProviderFactories: testutils.ProviderFactories,
3637
CheckDestroy: resource.ComposeTestCheckFunc(
3738
testAccFolderCheckDestroy(&folderA),
3839
testAccFolderCheckDestroy(&folderB),
3940
),
4041
Steps: []resource.TestStep{
4142
{
42-
Config: testAccExample(t, "data-sources/grafana_folders/data-source.tf"),
43+
Config: testutils.TestAccExample(t, "data-sources/grafana_folders/data-source.tf"),
4344
Check: resource.ComposeTestCheckFunc(checks...),
4445
},
4546
},

provider/data_source_library_panel_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import (
44
"testing"
55

66
gapi "github.com/grafana/grafana-api-golang-client"
7+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
78
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
89
)
910

1011
func TestAccDatasourceLibraryPanel(t *testing.T) {
11-
CheckOSSTestsEnabled(t)
12-
CheckOSSTestsSemver(t, ">=8.0.0")
12+
testutils.CheckOSSTestsEnabled(t)
13+
testutils.CheckOSSTestsSemver(t, ">=8.0.0")
1314

1415
var panel gapi.LibraryPanel
1516
// var dashboard gapi.Dashboard
@@ -31,11 +32,11 @@ func TestAccDatasourceLibraryPanel(t *testing.T) {
3132

3233
// TODO: Make parallelizable
3334
resource.Test(t, resource.TestCase{
34-
ProviderFactories: testAccProviderFactories,
35+
ProviderFactories: testutils.ProviderFactories,
3536
CheckDestroy: testAccLibraryPanelCheckDestroy(&panel),
3637
Steps: []resource.TestStep{
3738
{
38-
Config: testAccExample(t, "data-sources/grafana_library_panel/data-source.tf"),
39+
Config: testutils.TestAccExample(t, "data-sources/grafana_library_panel/data-source.tf"),
3940
Check: resource.ComposeTestCheckFunc(checks...),
4041
},
4142
},

provider/data_source_oncall_action_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ import (
55
"regexp"
66
"testing"
77

8+
"github.com/grafana/terraform-provider-grafana/provider/testutils"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
)
1112

1213
func TestAccDataSourceOnCallAction_Basic(t *testing.T) {
13-
CheckCloudInstanceTestsEnabled(t)
14+
testutils.CheckCloudInstanceTestsEnabled(t)
1415

1516
actionName := fmt.Sprintf("test-acc-%s", acctest.RandString(8))
1617

1718
resource.ParallelTest(t, resource.TestCase{
18-
ProviderFactories: testAccProviderFactories,
19+
ProviderFactories: testutils.ProviderFactories,
1920
Steps: []resource.TestStep{
2021
{
2122
Config: testAccDataSourceOnCallActionConfig(actionName),

0 commit comments

Comments
 (0)