Skip to content

Commit

Permalink
chore: refactor golden tests for autopopulation feature (#2446)
Browse files Browse the repository at this point in the history
As a clean-up follow up to
#2353, this PR
refactors the unit golden tests for the autopopulation feature to a
separate, new proto called `auto_populate_field_testing.proto`.
  • Loading branch information
alicejli authored Feb 8, 2024
1 parent cbed743 commit 33ba423
Show file tree
Hide file tree
Showing 27 changed files with 847 additions and 327 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,6 @@ public void createSimpleMessage_containsMessagesEnumsAndResourceName() {
"EchoRequest.newBuilder().setName("
+ "FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())"
+ ".setParent(FoobarName.ofProjectFoobarName(\"[PROJECT]\", \"[FOOBAR]\").toString())"
+ ".setRequestId(\"requestId693933066\")"
+ ".setSecondRequestId(\"secondRequestId344404470\")"
+ ".setThirdRequestId(true)"
+ ".setFourthRequestId(\"fourthRequestId-2116417776\")"
+ ".setFifthRequestId(\"fifthRequestId959024147\")"
+ ".setSixthRequestId(\"sixthRequestId1005218260\")"
+ ".setSeverity(Severity.forNumber(0))"
+ ".setFoobar(Foobar.newBuilder().build()).build()",
writerVisitor.write());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ public void generateGrpcServiceStubClass_createBatchingCallable() {
Assert.assertGoldenClass(this.getClass(), clazz, "GrpcLoggingStub.golden");
Assert.assertEmptySamples(clazz.samples());
}

@Test
public void generateGrpcServiceStubClass_autopopulateField() {
GapicContext context = GrpcTestProtoLoader.instance().parseAutoPopulateFieldTesting();
Service service = context.services().get(0);
GapicClass clazz = GrpcServiceStubClassComposer.instance().generate(context, service);

Assert.assertGoldenClass(this.getClass(), clazz, "GrpcAutoPopulateFieldStub.golden");
Assert.assertEmptySamples(clazz.samples());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down Expand Up @@ -552,12 +546,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand All @@ -583,11 +571,7 @@ public class EchoClient implements BackgroundResource {
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (EchoClient echoClient = EchoClient.create()) {
* ExpandRequest request =
* ExpandRequest.newBuilder()
* .setContent("content951530617")
* .setInfo("info3237038")
* .setRequestId("requestId693933066")
* .build();
* ExpandRequest.newBuilder().setContent("content951530617").setInfo("info3237038").build();
* ServerStream<EchoResponse> stream = echoClient.expandCallable().call(request);
* for (EchoResponse response : stream) {
* // Do something when a response is received.
Expand Down Expand Up @@ -633,12 +617,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down Expand Up @@ -666,12 +644,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down Expand Up @@ -702,12 +674,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down Expand Up @@ -1116,12 +1082,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down Expand Up @@ -1151,12 +1111,6 @@ public class EchoClient implements BackgroundResource {
* EchoRequest.newBuilder()
* .setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
* .setRequestId("requestId693933066")
* .setSecondRequestId("secondRequestId344404470")
* .setThirdRequestId(true)
* .setFourthRequestId("fourthRequestId-2116417776")
* .setFifthRequestId("fifthRequestId959024147")
* .setSixthRequestId("sixthRequestId1005218260")
* .setSeverity(Severity.forNumber(0))
* .setFoobar(Foobar.newBuilder().build())
* .build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand Down Expand Up @@ -409,11 +403,7 @@ public class EchoClientTest {
.build();
mockEcho.addResponse(expectedResponse);
ExpandRequest request =
ExpandRequest.newBuilder()
.setContent("content951530617")
.setInfo("info3237038")
.setRequestId("requestId693933066")
.build();
ExpandRequest.newBuilder().setContent("content951530617").setInfo("info3237038").build();

MockStreamObserver<EchoResponse> responseObserver = new MockStreamObserver<>();

Expand All @@ -430,11 +420,7 @@ public class EchoClientTest {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockEcho.addException(exception);
ExpandRequest request =
ExpandRequest.newBuilder()
.setContent("content951530617")
.setInfo("info3237038")
.setRequestId("requestId693933066")
.build();
ExpandRequest.newBuilder().setContent("content951530617").setInfo("info3237038").build();

MockStreamObserver<EchoResponse> responseObserver = new MockStreamObserver<>();

Expand Down Expand Up @@ -463,12 +449,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand All @@ -494,12 +474,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand Down Expand Up @@ -533,12 +507,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand All @@ -564,12 +532,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand Down Expand Up @@ -603,12 +565,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand All @@ -634,12 +590,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand Down Expand Up @@ -898,12 +848,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand All @@ -917,12 +861,6 @@ public class EchoClientTest {

Assert.assertEquals(request.getName(), actualRequest.getName());
Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getRequestId(), actualRequest.getRequestId());
Assert.assertEquals(request.getSecondRequestId(), actualRequest.getSecondRequestId());
Assert.assertEquals(request.getThirdRequestId(), actualRequest.getThirdRequestId());
Assert.assertEquals(request.getFourthRequestId(), actualRequest.getFourthRequestId());
Assert.assertEquals(request.getFifthRequestId(), actualRequest.getFifthRequestId());
Assert.assertEquals(request.getSixthRequestId(), actualRequest.getSixthRequestId());
Assert.assertEquals(request.getContent(), actualRequest.getContent());
Assert.assertEquals(request.getError(), actualRequest.getError());
Assert.assertEquals(request.getSeverity(), actualRequest.getSeverity());
Expand All @@ -943,12 +881,6 @@ public class EchoClientTest {
EchoRequest.newBuilder()
.setName(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setParent(FoobarName.ofProjectFoobarName("[PROJECT]", "[FOOBAR]").toString())
.setRequestId("requestId693933066")
.setSecondRequestId("secondRequestId344404470")
.setThirdRequestId(true)
.setFourthRequestId("fourthRequestId-2116417776")
.setFifthRequestId("fifthRequestId959024147")
.setSixthRequestId("sixthRequestId1005218260")
.setSeverity(Severity.forNumber(0))
.setFoobar(Foobar.newBuilder().build())
.build();
Expand Down
Loading

0 comments on commit 33ba423

Please sign in to comment.