Skip to content

Commit

Permalink
Merge pull request #35334 from hashicorp/td-endpoint-tests-simple-sdkv2
Browse files Browse the repository at this point in the history
Adds endpoint tests for services implemented with AWS SDK v2, no aliases, and no custom envvars
  • Loading branch information
gdavison authored Jan 18, 2024
2 parents 68f1f9d + c249ccc commit 6b12808
Show file tree
Hide file tree
Showing 97 changed files with 42,238 additions and 163 deletions.
3 changes: 3 additions & 0 deletions .ci/.semgrep-caps-aws-ec2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ rules:
exclude:
- internal/service/securitylake/aws_log_source.go
- internal/service/securitylake/aws_log_source_test.go
- internal/service/*/service_endpoints_gen_test.go
patterns:
- pattern: func $NAME( ... ) { ... }
- metavariable-pattern:
Expand All @@ -27,6 +28,7 @@ rules:
- internal
exclude:
- internal/service/securitylake/aws_log_source.go
- internal/service/*/service_endpoints_gen_test.go
patterns:
- pattern: const $NAME = ...
- metavariable-pattern:
Expand All @@ -44,6 +46,7 @@ rules:
exclude:
- internal/service/securitylake/aws_log_source.go
- internal/service/securitylake/exports_test.go
- internal/service/*/service_endpoints_gen_test.go
patterns:
- pattern: var $NAME = ...
- metavariable-pattern:
Expand Down
4 changes: 4 additions & 0 deletions .ci/semgrep/migrate/context.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ rules:
- pattern-not: conn.Handlers.$X(...)
- pattern-not: conn.Handlers.$X.$Y(...)
- pattern-not: conn.Options()
- pattern-not: codestarconnections_sdkv2.$API()
- pattern-not: connectcases_sdkv2.$API()
- pattern-not: mediaconnect_sdkv2.$API()
- pattern-not: pcaconnectorad_sdkv2.$API()
severity: ERROR
- id: context-todo
languages: [go]
Expand Down
11 changes: 2 additions & 9 deletions internal/generate/awsclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ func main() {
GoV2Package: l.GoV2Package(),
}

if l.ClientSDKV1() != "" {
s.SDKVersion = "1"
s.SDKVersion = l.SDKVersion()
if l.ClientSDKV1() {
s.GoV1ClientTypeName = l.GoV1ClientTypeName()
}
if l.ClientSDKV2() != "" {
if l.ClientSDKV1() != "" {
s.SDKVersion = "1,2"
} else {
s.SDKVersion = "2"
}
}

td.Services = append(td.Services, s)
}
Expand Down
16 changes: 11 additions & 5 deletions internal/generate/checknames/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
lineOffset = 1 // translate from 0-based to 1-based index
lineOffset = 2 // 1 for skipping header line + 1 to translate from 0-based to 1-based index
)

// DocPrefix tests/column needs to be reworked for compatibility with tfproviderdocs
Expand Down Expand Up @@ -98,15 +98,15 @@ func main() {
}
}

if l.ClientSDKV1() == "" && l.ClientSDKV2() == "" && !l.Exclude() {
if !l.ClientSDKV1() && !l.ClientSDKV2() && !l.Exclude() {
log.Fatalf("in service data, line %d, for service %s, at least one of ClientSDKV1 or ClientSDKV2 must have a value if Exclude is blank", i+lineOffset, l.HumanFriendly())
}

if l.ClientSDKV1() != "" && (l.GoV1Package() == "" || l.GoV1ClientTypeName() == "") {
if l.ClientSDKV1() && (l.GoV1Package() == "" || l.GoV1ClientTypeName() == "") {
log.Fatalf("in service data, line %d, for service %s, SDKVersion is set to 1 so neither GoV1Package nor GoV1ClientTypeName can be blank", i+lineOffset, l.HumanFriendly())
}

if l.ClientSDKV2() != "" && l.GoV2Package() == "" {
if l.ClientSDKV2() && l.GoV2Package() == "" {
log.Fatalf("in service data, line %d, for service %s, SDKVersion is set to 2 so GoV2Package cannot be blank", i+lineOffset, l.HumanFriendly())
}

Expand Down Expand Up @@ -177,6 +177,12 @@ func main() {
log.Printf("in service data, line %d, for service %s, SdkId is required unless Exclude is set", i+lineOffset, l.HumanFriendly())
}

if l.EndpointAPICall() == "" {
if l.ClientSDKV2() && len(l.Aliases()) == 0 && l.DeprecatedEnvVar() == "" && l.TfAwsEnvVar() == "" {
log.Printf("in service data, line %d, for service %s, EndpointAPICall is required for SDKv2 services without aliases or custom envvars", i+lineOffset, l.HumanFriendly())
}
}

rre := l.ResourcePrefixActual()

if rre == "" {
Expand All @@ -191,7 +197,7 @@ func main() {

allChecks++
}
fmt.Printf(" Performed %d checks on service data, 0 errors.\n", (allChecks * 39))
fmt.Printf(" Performed %d checks on service data, 0 errors.\n", (allChecks * 40))

var fileErrs bool

Expand Down
3 changes: 3 additions & 0 deletions internal/generate/serviceendpointtests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# serviceendpointtests

The `serviceendpointtests` generator creates tests for endpoint configuration precedence.
Loading

0 comments on commit 6b12808

Please sign in to comment.