Skip to content

Commit 8f2dd23

Browse files
authored
add test that verifies SRA order of operations (#3025)
1 parent 3d547b0 commit 8f2dd23

File tree

824 files changed

+599202
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

824 files changed

+599202
-1
lines changed

.changelog/95191f0d1ce44022aa8cc3ff1871bbb2.json

Lines changed: 409 additions & 0 deletions
Large diffs are not rendered by default.

SMITHY_GO_CODEGEN_VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b5c304bb2a4b0306cb8de41bf2d842fe4e76eaf6
1+
af7d6d6b39cbb90e1dd09fcec8bc7c7e8883b2a9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package software.amazon.smithy.aws.go.codegen.customization;
2+
3+
import software.amazon.smithy.go.codegen.GoCodegenContext;
4+
import software.amazon.smithy.go.codegen.GoWriter;
5+
import software.amazon.smithy.go.codegen.SmithyGoDependency;
6+
import software.amazon.smithy.go.codegen.integration.GoIntegration;
7+
import software.amazon.smithy.model.knowledge.TopDownIndex;
8+
9+
import static software.amazon.smithy.go.codegen.GoWriter.goTemplate;
10+
11+
/**
12+
* Validates that service client operations are performed in the orders specified by the Smithy Reference Architecture (SRA).
13+
*/
14+
public class SraOperationOrderTest implements GoIntegration {
15+
@Override
16+
public void writeAdditionalFiles(GoCodegenContext ctx) {
17+
ctx.writerDelegator().useFileWriter("sra_operation_order_test.go", ctx.settings().getModuleName(), writer -> {
18+
writer.write(renderCommonTestSource());
19+
20+
TopDownIndex.of(ctx.model())
21+
.getContainedOperations(ctx.settings().getService(ctx.model()))
22+
.forEach(it -> {
23+
var operationName = ctx.symbolProvider().toSymbol(it).getName();
24+
writer.write(renderTest(operationName));
25+
});
26+
});
27+
}
28+
29+
private GoWriter.Writable renderCommonTestSource() {
30+
return goTemplate("""
31+
$D $D
32+
var errTestReturnEarly = errors.New("errTestReturnEarly")
33+
34+
func captureMiddlewareStack(stack *middleware.Stack) func(*middleware.Stack) error {
35+
return func(inner *middleware.Stack) error {
36+
*stack = *inner
37+
return errTestReturnEarly
38+
}
39+
}
40+
""", SmithyGoDependency.ERRORS, SmithyGoDependency.SMITHY_MIDDLEWARE);
41+
}
42+
43+
private GoWriter.Writable renderTest(String operationName) {
44+
return goTemplate("""
45+
$1D $2D $3D $4D $5D $6D
46+
func TestOp$7LSRAOperationOrder(t *testing.T) {
47+
expect := []string{
48+
"OperationSerializer",
49+
"Retry",
50+
"ResolveAuthScheme",
51+
"GetIdentity",
52+
"ResolveEndpointV2",
53+
"Signing",
54+
"OperationDeserializer",
55+
}
56+
57+
var captured middleware.Stack
58+
svc := New(Options{
59+
APIOptions: []func(*middleware.Stack) error{
60+
captureMiddlewareStack(&captured),
61+
},
62+
})
63+
_, err := svc.$7L(context.Background(), nil)
64+
if err != nil && !errors.Is(err, errTestReturnEarly) {
65+
t.Fatalf("unexpected error: %v", err)
66+
}
67+
68+
var actual, all []string
69+
for _, step := range strings.Split(captured.String(), "\\n") {
70+
trimmed := strings.TrimSpace(step)
71+
all = append(all, trimmed)
72+
if slices.Contains(expect, trimmed) {
73+
actual = append(actual, trimmed)
74+
}
75+
}
76+
77+
if !slices.Equal(expect, actual) {
78+
t.Errorf("order mismatch:\\nexpect: %v\\nactual: %v\\nall: %v", expect, actual, all)
79+
}
80+
}
81+
""",
82+
SmithyGoDependency.ERRORS,
83+
SmithyGoDependency.TESTING,
84+
SmithyGoDependency.CONTEXT,
85+
SmithyGoDependency.STRINGS,
86+
SmithyGoDependency.SLICES,
87+
SmithyGoDependency.SMITHY_MIDDLEWARE,
88+
operationName
89+
);
90+
}
91+
}

codegen/smithy-aws-go-codegen/src/main/resources/META-INF/services/software.amazon.smithy.go.codegen.integration.GoIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ software.amazon.smithy.aws.go.codegen.customization.BasicUserAgentFeatures
9090
software.amazon.smithy.aws.go.codegen.customization.ChecksumMetricsTracking
9191
software.amazon.smithy.aws.go.codegen.customization.AccountIdEndpointModeUserAgent
9292
software.amazon.smithy.aws.go.codegen.CredentialSourceFeatureTrackerGenerator
93+
software.amazon.smithy.aws.go.codegen.customization.SraOperationOrderTest

internal/kitchensinktest/generated.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"protocol_test.go",
2424
"serializers.go",
2525
"snapshot_test.go",
26+
"sra_operation_order_test.go",
2627
"types/errors.go",
2728
"types/types.go",
2829
"validators.go"

internal/kitchensinktest/sra_operation_order_test.go

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/protocoltest/awsrestjson/generated.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
"protocol_test.go",
200200
"serializers.go",
201201
"snapshot_test.go",
202+
"sra_operation_order_test.go",
202203
"types/enums.go",
203204
"types/errors.go",
204205
"types/types.go",

0 commit comments

Comments
 (0)