11package grafana_test
22
33import (
4+ "strconv"
45 "testing"
56
67 "github.com/grafana/grafana-openapi-client-go/models"
@@ -12,30 +13,41 @@ func TestAccDatasourceRole_basic(t *testing.T) {
1213 testutils .CheckEnterpriseTestsEnabled (t , ">=9.0.0" )
1314
1415 var role models.RoleDTO
15- checks := []resource.TestCheckFunc {
16- roleCheckExists .exists ("grafana_role.test" , & role ),
17- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "name" , "test-role" ),
18- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "description" , "test-role description" ),
19- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "uid" , "test-ds-role-uid" ),
20- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "version" , "1" ),
21- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "global" , "true" ),
22- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.#" , "3" ),
23- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.0.action" , "org.users:add" ),
24- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.0.scope" , "users:*" ),
25- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.1.action" , "org.users:read" ),
26- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.1.scope" , "users:*" ),
27- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.2.action" , "org.users:write" ),
28- resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.2.scope" , "users:*" ),
29- }
16+ for _ , hidden := range []bool {false , true } {
17+ formatted := strconv .FormatBool (hidden )
18+ t .Run ("hidden=" + formatted , func (t * testing.T ) {
19+ config := testutils .TestAccExample (t , "data-sources/grafana_role/data-source.tf" )
20+ if hidden {
21+ config = testutils .TestAccExampleWithReplace (t , "data-sources/grafana_role/data-source.tf" , map [string ]string {
22+ `hidden = false` : `hidden = true` ,
23+ })
24+ }
3025
31- resource .ParallelTest (t , resource.TestCase {
32- ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
33- CheckDestroy : roleCheckExists .destroyed (& role , nil ),
34- Steps : []resource.TestStep {
35- {
36- Config : testutils .TestAccExample (t , "data-sources/grafana_role/data-source.tf" ),
37- Check : resource .ComposeTestCheckFunc (checks ... ),
38- },
39- },
40- })
26+ resource .ParallelTest (t , resource.TestCase {
27+ ProtoV5ProviderFactories : testutils .ProtoV5ProviderFactories ,
28+ CheckDestroy : roleCheckExists .destroyed (& role , nil ),
29+ Steps : []resource.TestStep {
30+ {
31+ Config : config ,
32+ Check : resource .ComposeTestCheckFunc (
33+ roleCheckExists .exists ("grafana_role.test" , & role ),
34+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "name" , "test-role" ),
35+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "description" , "test-role description" ),
36+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "uid" , "test-ds-role-uid" ),
37+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "version" , "1" ),
38+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "global" , "true" ),
39+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "hidden" , formatted ),
40+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.#" , "3" ),
41+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.0.action" , "org.users:add" ),
42+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.0.scope" , "users:*" ),
43+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.1.action" , "org.users:read" ),
44+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.1.scope" , "users:*" ),
45+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.2.action" , "org.users:write" ),
46+ resource .TestCheckResourceAttr ("data.grafana_role.from_name" , "permissions.2.scope" , "users:*" ),
47+ ),
48+ },
49+ },
50+ })
51+ })
52+ }
4153}
0 commit comments