Skip to content

Commit 786739f

Browse files
Consistent uid and id regexes (#313)
1 parent 9ded25e commit 786739f

9 files changed

+17
-18
lines changed

grafana/data_source_folder_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package grafana
22

33
import (
4-
"regexp"
54
"testing"
65

76
gapi "github.com/grafana/grafana-api-golang-client"
@@ -18,10 +17,10 @@ func TestAccDatasourceFolder(t *testing.T) {
1817
"data.grafana_folder.from_title", "title", "test-folder",
1918
),
2019
resource.TestMatchResourceAttr(
21-
"data.grafana_folder.from_title", "id", regexp.MustCompile(`^\d+$`),
20+
"data.grafana_folder.from_title", "id", idRegexp,
2221
),
2322
resource.TestMatchResourceAttr(
24-
"data.grafana_folder.from_title", "uid", regexp.MustCompile(`^[a-zA-Z0-9-]+$`),
23+
"data.grafana_folder.from_title", "uid", uidRegexp,
2524
),
2625
}
2726

grafana/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io/ioutil"
99
"net/url"
10+
"regexp"
1011
"strings"
1112

1213
"github.com/hashicorp/go-cleanhttp"
@@ -18,6 +19,11 @@ import (
1819
smapi "github.com/grafana/synthetic-monitoring-api-go-client"
1920
)
2021

22+
var (
23+
idRegexp = regexp.MustCompile(`^\d+$`)
24+
uidRegexp = regexp.MustCompile(`^[a-zA-Z0-9-_]+$`)
25+
)
26+
2127
func init() {
2228
schema.DescriptionKind = schema.StringMarkdown
2329
schema.SchemaDescriptionBuilder = func(s *schema.Schema) string {

grafana/resource_alert_notification_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func TestAccAlertNotification_basic(t *testing.T) {
3131
"grafana_alert_notification.test", "type", "email",
3232
),
3333
resource.TestMatchResourceAttr(
34-
"grafana_alert_notification.test", "id", regexp.MustCompile(`\d+`),
34+
"grafana_alert_notification.test", "id", idRegexp,
3535
),
3636
resource.TestCheckResourceAttr(
3737
"grafana_alert_notification.test", "send_reminder", "true",
@@ -70,7 +70,7 @@ func TestAccAlertNotification_disableResolveMessage(t *testing.T) {
7070
"grafana_alert_notification.test", "type", "email",
7171
),
7272
resource.TestMatchResourceAttr(
73-
"grafana_alert_notification.test", "id", regexp.MustCompile(`\d+`),
73+
"grafana_alert_notification.test", "id", idRegexp,
7474
),
7575
resource.TestCheckResourceAttr(
7676
"grafana_alert_notification.test", "send_reminder", "true",

grafana/resource_dashboard_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"testing"
76

87
gapi "github.com/grafana/grafana-api-golang-client"
@@ -157,7 +156,7 @@ func TestAccDashboard_folder(t *testing.T) {
157156
resource.TestCheckResourceAttr("grafana_dashboard.test_folder", "id", "folder"),
158157
resource.TestCheckResourceAttr("grafana_dashboard.test_folder", "uid", "folder"),
159158
resource.TestMatchResourceAttr(
160-
"grafana_dashboard.test_folder", "folder", regexp.MustCompile(`\d+`),
159+
"grafana_dashboard.test_folder", "folder", idRegexp,
161160
),
162161
),
163162
},

grafana/resource_data_source_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"strconv"
76
"testing"
87

@@ -307,7 +306,7 @@ func TestAccDataSource_basic(t *testing.T) {
307306
resource.TestMatchResourceAttr(
308307
test.resource,
309308
"id",
310-
regexp.MustCompile(`\d+`),
309+
idRegexp,
311310
),
312311
}
313312

grafana/resource_folder_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"strconv"
76
"testing"
87

@@ -27,10 +26,10 @@ func TestAccFolder_basic(t *testing.T) {
2726
Check: resource.ComposeTestCheckFunc(
2827
testAccFolderCheckExists("grafana_folder.test_folder", &folder),
2928
resource.TestMatchResourceAttr(
30-
"grafana_folder.test_folder", "id", regexp.MustCompile(`\d+`),
29+
"grafana_folder.test_folder", "id", idRegexp,
3130
),
3231
resource.TestMatchResourceAttr(
33-
"grafana_folder.test_folder", "uid", regexp.MustCompile(`\w+`),
32+
"grafana_folder.test_folder", "uid", uidRegexp,
3433
),
3534
),
3635
},

grafana/resource_organization_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"strconv"
76
"testing"
87

@@ -29,7 +28,7 @@ func TestAccOrganization_basic(t *testing.T) {
2928
"grafana_organization.test", "name", "terraform-acc-test",
3029
),
3130
resource.TestMatchResourceAttr(
32-
"grafana_organization.test", "id", regexp.MustCompile(`\d+`),
31+
"grafana_organization.test", "id", idRegexp,
3332
),
3433
),
3534
},

grafana/resource_team_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"strconv"
76
"testing"
87

@@ -32,7 +31,7 @@ func TestAccTeam_basic(t *testing.T) {
3231
"grafana_team.test", "email", "[email protected]",
3332
),
3433
resource.TestMatchResourceAttr(
35-
"grafana_team.test", "id", regexp.MustCompile(`\d+`),
34+
"grafana_team.test", "id", idRegexp,
3635
),
3736
),
3837
},

grafana/resource_user_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grafana
22

33
import (
44
"fmt"
5-
"regexp"
65
"strconv"
76
"testing"
87

@@ -38,7 +37,7 @@ func TestAccUser_basic(t *testing.T) {
3837
"grafana_user.test", "password", "abc123",
3938
),
4039
resource.TestMatchResourceAttr(
41-
"grafana_user.test", "id", regexp.MustCompile(`\d+`),
40+
"grafana_user.test", "id", idRegexp,
4241
),
4342
),
4443
},

0 commit comments

Comments
 (0)