Skip to content

Commit

Permalink
Merge pull request #36517 from hashicorp/td-generate-tagstests-batch
Browse files Browse the repository at this point in the history
Generated tagging acceptance tests for Batch resources
  • Loading branch information
gdavison committed Apr 4, 2024
2 parents 604d3c6 + b08eaba commit 05602be
Show file tree
Hide file tree
Showing 17 changed files with 3,048 additions and 146 deletions.
3 changes: 3 additions & 0 deletions .changelog/36517.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_batch_scheduling_policy: Fixes error where tags could not be updated
```
9 changes: 9 additions & 0 deletions internal/generate/tagstests/file.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags(t *testing.T) {
}

func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags_null(t *testing.T) {
{{- if eq .Implementation "framework" }}
t.Skip("Tags with null values are not correctly handled with the Plugin Framework")
{{ end }}
{{- template "Init" . }}

resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -496,6 +499,9 @@ func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags_DefaultTags_emptyResourceTa
}

func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags_DefaultTags_nullOverlappingResourceTag(t *testing.T) {
{{- if eq .Implementation "framework" }}
t.Skip("Tags with null values are not correctly handled with the Plugin Framework")
{{ end }}
{{- template "Init" . }}

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -519,6 +525,9 @@ func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags_DefaultTags_nullOverlapping
}

func TestAcc{{ .ProviderNameUpper }}{{ .Name }}_tags_DefaultTags_nullNonOverlappingResourceTag(t *testing.T) {
{{- if eq .Implementation "framework" }}
t.Skip("Tags with null values are not correctly handled with the Plugin Framework")
{{ end }}
{{- template "Init" . }}

resource.ParallelTest(t, resource.TestCase{
Expand Down
10 changes: 10 additions & 0 deletions internal/generate/tagstests/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ func main() {
}
}

type implementation string

const (
implementationFramework implementation = "framework"
implementationSDK implementation = "sdk"
)

type ResourceDatum struct {
ProviderPackage string
ProviderNameUpper string
Expand All @@ -101,6 +108,7 @@ type ResourceDatum struct {
FileName string
Generator string
ImportIgnore []string
Implementation implementation
}

//go:embed file.tmpl
Expand Down Expand Up @@ -174,6 +182,7 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
if m := annotation.FindStringSubmatch(line); len(m) > 0 {
switch annotationName := m[1]; annotationName {
case "FrameworkResource":
d.Implementation = implementationFramework
args := common.ParseArgs(m[3])
if len(args.Positional) == 0 {
v.errs = append(v.errs, fmt.Errorf("no type name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
Expand All @@ -185,6 +194,7 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
}

case "SDKResource":
d.Implementation = implementationSDK
args := common.ParseArgs(m[3])
if len(args.Positional) == 0 {
v.errs = append(v.errs, fmt.Errorf("no type name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
Expand Down
1 change: 1 addition & 0 deletions internal/service/batch/compute_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (

// @SDKResource("aws_batch_compute_environment", name="Compute Environment")
// @Tags(identifierAttribute="arn")
// @Testing(existsType="github.com/aws/aws-sdk-go/service/batch.ComputeEnvironmentDetail")
func ResourceComputeEnvironment() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceComputeEnvironmentCreate,
Expand Down
Loading

0 comments on commit 05602be

Please sign in to comment.