Skip to content

Commit

Permalink
Merge pull request #33164 from hashicorp/d-update-docs-skaff-regexache
Browse files Browse the repository at this point in the history
skaff, docs: Update for regexache
  • Loading branch information
YakDriver authored Aug 23, 2023
2 parents b86fbe4 + a5f0b73 commit 6a96486
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .ci/providerlint/passes/AWSAT001/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Otherwise, available ARN testing check functions include:
## Flagged Code

```go
resource.TestMatchResourceAttr("aws_lb_listener.test", "certificate_arn", regexp.MustCompile(`^arn:[^:]+:acm:[^:]+:[^:]+:certificate/.+$`))
resource.TestMatchResourceAttr("aws_lb_listener.test", "certificate_arn", regexache.MustCompile(`^arn:[^:]+:acm:[^:]+:[^:]+:certificate/.+$`))
```

## Passing Code

```go
resource.TestCheckResourceAttrPair("aws_lb_listener.test", "certificate_arn", "aws_acm_certificate.test", "arn")

acctest.MatchResourceAttrRegionalARN("aws_lb_listener.test", "certificate_arn", "acm", regexp.MustCompile(`certificate/.+`))
acctest.MatchResourceAttrRegionalARN("aws_lb_listener.test", "certificate_arn", "acm", regexache.MustCompile(`certificate/.+`))
```

## Ignoring Check
Expand All @@ -41,5 +41,5 @@ The check can be ignored for a certain line via a `//lintignore:AWSAT001` commen

```go
//lintignore:AWSAT001
resource.TestMatchResourceAttr("aws_lb_listener.test", "certificate_arn", regexp.MustCompile(`^arn:[^:]+:acm:[^:]+:[^:]+:certificate/.+$`))
resource.TestMatchResourceAttr("aws_lb_listener.test", "certificate_arn", regexache.MustCompile(`^arn:[^:]+:acm:[^:]+:[^:]+:certificate/.+$`))
```
5 changes: 2 additions & 3 deletions .ci/providerlint/passes/AWSAT001/testdata/src/a/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package a

import (
"regexp"

"github.com/YakDriver/regexache"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

const resourceName = `aws_example_thing.test`

var testRegexp = regexp.MustCompile(`.*`)
var testRegexp = regexache.MustCompile(`.*`)

func f() {
/* Passing cases */
Expand Down
2 changes: 1 addition & 1 deletion docs/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func TestAccVPCFlowLog_destinationError(t *testing.T) {
Config: testAccVPCFlowLogConfig_destinationError(rName),
// This error should not happen!
// See https://github.com/hashicorp/terraform-provider-aws/issues/45912
ExpectError: regexp.MustCompile(`invalid destination`),
ExpectError: regexache.MustCompile(`invalid destination`),
},
},
})
Expand Down
5 changes: 3 additions & 2 deletions skaff/datasource/datasourcetest.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ import (
// types.<Type Name>.
{{- end }}
"fmt"
"regexp"
"strings"
"testing"

"github.com/YakDriver/regexache"
{{ if .AWSGoSDKV2 }}
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/{{ .ServicePackage }}"
Expand Down Expand Up @@ -200,7 +201,7 @@ func TestAcc{{ .Service }}{{ .DataSource }}DataSource_basic(t *testing.T) {
"username": "Test",
"password": "TestTest1234",
}),
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "{{ .ServicePackage }}", regexp.MustCompile(`{{ .DataSourceLower }}:+.`)),
acctest.MatchResourceAttrRegionalARN(dataSourceName, "arn", "{{ .ServicePackage }}", regexache.MustCompile(`{{ .DataSourceLower }}:+.`)),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions skaff/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/hashicorp/terraform-provider-aws/skaff
go 1.20

require (
github.com/YakDriver/regexache v0.7.0
github.com/hashicorp/terraform-provider-aws v1.60.1-0.20220322001452-8f7a597d0c24
github.com/spf13/cobra v1.7.0
)
Expand Down
2 changes: 2 additions & 0 deletions skaff/go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/YakDriver/regexache v0.7.0 h1:Mo0i2uUsRVbK+waHJ4+QPh/l7WknyQzCgAlMViSKa8w=
github.com/YakDriver/regexache v0.7.0/go.mod h1:mD8oVCndzUi1Qig4J/wY6aF5SOdqyyGopfTjP8ePBP8=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down
10 changes: 5 additions & 5 deletions skaff/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (
"io/fs"
"os"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/YakDriver/regexache"
"github.com/hashicorp/terraform-provider-aws/names"
)

Expand Down Expand Up @@ -52,18 +52,18 @@ func ToSnakeCase(upper string, snakeName string) string {
return snakeName
}

re := regexp.MustCompile(`([a-z])([A-Z]{2,})`)
re := regexache.MustCompile(`([a-z])([A-Z]{2,})`)
upper = re.ReplaceAllString(upper, `${1}_${2}`)

re2 := regexp.MustCompile(`([A-Z][a-z])`)
re2 := regexache.MustCompile(`([A-Z][a-z])`)
return strings.TrimPrefix(strings.ToLower(re2.ReplaceAllString(upper, `_$1`)), "_")
}

func HumanResName(upper string) string {
re := regexp.MustCompile(`([a-z])([A-Z]{2,})`)
re := regexache.MustCompile(`([a-z])([A-Z]{2,})`)
upper = re.ReplaceAllString(upper, `${1} ${2}`)

re2 := regexp.MustCompile(`([A-Z][a-z])`)
re2 := regexache.MustCompile(`([A-Z][a-z])`)
return strings.TrimPrefix(re2.ReplaceAllString(upper, ` $1`), " ")
}

Expand Down
4 changes: 3 additions & 1 deletion skaff/resource/resourcetest.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import (
"regexp"
"strings"
"testing"

"github.com/YakDriver/regexache"
{{ if .AWSGoSDKV2 }}
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/{{ .ServicePackage }}"
Expand Down Expand Up @@ -202,7 +204,7 @@ func TestAcc{{ .Service }}{{ .Resource }}_basic(t *testing.T) {
"username": "Test",
"password": "TestTest1234",
}),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "{{ .ServicePackage }}", regexp.MustCompile(`{{ .ResourceLower }}:+.`)),
acctest.MatchResourceAttrRegionalARN(resourceName, "arn", "{{ .ServicePackage }}", regexache.MustCompile(`{{ .ResourceLower }}:+.`)),
),
},
{
Expand Down

0 comments on commit 6a96486

Please sign in to comment.