@@ -185,7 +185,7 @@ private void generateServerOperationTests(OperationShape operation, OperationInd
185
185
});
186
186
// 3. Generate test cases for each error on each operation.
187
187
for (StructureShape error : operationIndex .getErrors (operation )) {
188
- if (!error .hasTag ("server -only" )) {
188
+ if (!error .hasTag ("client -only" )) {
189
189
error .getTrait (HttpResponseTestsTrait .class ).ifPresent (trait -> {
190
190
for (HttpResponseTestCase testCase : trait .getTestCasesFor (AppliesTo .SERVER )) {
191
191
onlyIfProtocolMatches (testCase ,
@@ -537,14 +537,25 @@ private void generateServerErrorResponseTest(
537
537
Symbol outputType = operationSymbol .expectProperty ("outputType" , Symbol .class );
538
538
Symbol errorSymbol = serverSymbolProvider .toSymbol (error );
539
539
ErrorTrait errorTrait = error .expectTrait (ErrorTrait .class );
540
+
540
541
testCase .getDocumentation ().ifPresent (writer ::writeDocs );
541
542
String testName = testCase .getId () + ":ServerErrorResponse" ;
542
543
writer .openBlock ("it($S, async () => {" , "});\n " , testName , () -> {
544
+
545
+ // Generates a Partial implementation of the service type that only includes
546
+ // the specific operation under test. Later we'll have to "cast" this with an "as",
547
+ // but using the partial in the meantime will give us proper type checking on the
548
+ // operation we want.
543
549
writer .openBlock ("class TestService implements Partial<$T> {" , "}" , serviceSymbol , () -> {
544
550
writer .openBlock ("$L(input: any, request: HttpRequest): $T {" , "}" ,
545
551
operationSymbol .getName (), outputType , () -> {
552
+ // Write out an object according to what's defined in the test case.
546
553
writer .writeInline ("const response = " );
547
554
testCase .getParams ().accept (new CommandInputNodeVisitor (error , true ));
555
+
556
+ // Add in the necessary wrapping information to make the error satisfy its interface.
557
+ // TODO: having proper constructors for these errors would be really nice so we don't
558
+ // have to do this.
548
559
writer .openBlock ("const error: $T = {" , "};" , errorSymbol , () -> {
549
560
writer .write ("...response," );
550
561
writer .write ("name: $S," , error .getId ().getName ());
@@ -579,14 +590,19 @@ private void writeServerResponseTest(OperationShape operation, HttpResponseTestC
579
590
});
580
591
});
581
592
582
- writer . write ( "const request = new HttpRequest({method: 'POST', hostname: 'example.com'});" );
583
-
593
+ // Extend the existing serializer and replace the deserialize with a noop so we don't have to
594
+ // worry about trying to construct something that matches.
584
595
writer .openBlock ("class TestSerializer extends $T {" , "}" , serializerSymbol , () -> {
585
596
writer .openBlock ("deserialize = (output: any, context: any): Promise<any> => {" , "};" , () -> {
586
597
writer .write ("return Promise.resolve({});" );
587
598
});
588
599
});
589
600
601
+ // Since we aren't going through the deserializer, we don't have to put much in the fake request.
602
+ // Just enough to get it through our test mux.
603
+ writer .write ("const request = new HttpRequest({method: 'POST', hostname: 'example.com'});" );
604
+
605
+ // Create a new serializer factory that always returns our test serializer.
590
606
writer .addImport ("SmithyException" , "__SmithyException" , "@aws-sdk/smithy-client" );
591
607
writer .addImport ("OperationSerializer" , "__OperationSerializer" , "@aws-smithy/server-common" );
592
608
writer .openBlock ("const serFn: (op: $1T) => __OperationSerializer<$2T, $1T, __SmithyException> = (op) =>"
0 commit comments