Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ggj][infra][5/5] support goldens updates for composer tests #348

Merged
merged 22 commits into from
Oct 2, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,39 @@ java_binary(
name = "junit_runner",
srcs = [
"//src/test/java/com/google/api/generator/gapic/dummy:dummy_files",
"//src/test/java/com/google/api/generator/engine:engine_files",
"//src/test/java/com/google/api/generator/gapic/composer:composer_files",
"//src/test/java/com/google/api/generator/test/framework:framework_files",
],
data = ["//src/test/java/com/google/api/generator/gapic/dummy/goldens:goldens_files"],
data = [
"//src/test/java/com/google/api/generator/gapic/dummy/goldens:goldens_files",
"//src/test/java/com/google/api/generator/engine/goldens:goldens_files",
"//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files",
"//src/test/java/com/google/api/generator/gapic/testdata:gapic_config_files",
"//src/test/java/com/google/api/generator/gapic/testdata:service_config_files",
],
jvm_flags = ["-Xmx512m"],
main_class = "com.google.api.generator.test.framework.SingleJUnitTestRunner",
visibility = ["//visibility:public"],
deps = [
"//src/main/java/com/google/api/generator/engine/ast",
"//src/main/java/com/google/api/generator/engine/writer",
"//src/test/java/com/google/api/generator/test/framework",
"//src/main/java/com/google/api/generator/engine/lexicon",
"//src/main/java/com/google/api/generator/gapic/composer",
"//src/main/java/com/google/api/generator/gapic/model",
"//src/main/java/com/google/api/generator/gapic/protoparser",
"//src/test/java/com/google/api/generator/gapic/testdata:showcase_java_proto",
"//src/test/java/com/google/api/generator/gapic/testdata:testgapic_java_proto",
"//src/test/java/com/google/api/generator/gapic/composer:common_resources_java_proto",
"@com_google_guava_guava//:com_google_guava_guava",
"@com_google_api_gax_java//gax",
"@com_google_googleapis//google/logging/v2:logging_java_proto",
"@com_google_googleapis//google/pubsub/v1:pubsub_java_proto",
"@com_google_googleapis//google/rpc:rpc_java_proto",
"@com_google_protobuf//:protobuf_java",
"//:service_config_java_proto",
"@com_google_truth_truth//jar",
"@io_github_java_diff_utils//jar",
"@junit_junit//jar",
"@org_hamcrest_hamcrest_core//jar",
Expand Down
2 changes: 1 addition & 1 deletion rules_bazel/java/java_diff_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ junit_output_zip = rule(
),
},
outputs = {
"output": "%{name}%.zip",
"output": "%{name}.zip",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%{name}%.zip will generate zip file named test_output%.zip, removed the extra %

},
implementation = _junit_output_impl,
)
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/com/google/api/generator/engine/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//:rules_bazel/java/java_diff_test.bzl", "updated_golden")

package(default_visibility = ["//visibility:public"])

filegroup(
Expand All @@ -23,5 +25,21 @@ TESTS = [
"//src/main/java/com/google/api/generator/engine/writer",
"//src/test/java/com/google/api/generator/test/framework",
"@junit_junit//jar",
"@com_google_guava_guava//jar",
"@com_google_truth_truth//jar",
],
) for test_name in TESTS]

TEST_CLASS_NAME = "com.google.api.generator.engine.JavaCodeGeneratorTest"

# Run `bazel run src/test/java/com/google/api/generator/engine:JavaCodeGeneratorTest_update`
# to update goldens as expected generated code.
updated_golden(
name = "JavaCodeGeneratorTest_update",
srcs = [
":engine_files",
"//src/test/java/com/google/api/generator/engine/goldens:goldens_files",
"//src/test/java/com/google/api/generator/test/framework:framework_files",
],
test_class_name = TEST_CLASS_NAME,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.google.api.generator.engine.ast.WhileStatement;
import com.google.api.generator.engine.writer.JavaWriterVisitor;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -172,6 +173,8 @@ public void validJavaClass() {
.build();
JavaWriterVisitor javaWriterVisitor = new JavaWriterVisitor();
libraryServiceStubClass.accept(javaWriterVisitor);
Utils.saveCodegenToFile(
this.getClass(), "JavaCodeGeneratorTest.golden", javaWriterVisitor.write());
Path goldenFilePath = Paths.get(GOLDENFILES_DIRECTORY, "JavaCodeGeneratorTest.golden");
Assert.assertCodeEquals(goldenFilePath, javaWriterVisitor.write());
}
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/com/google/api/generator/gapic/composer/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
load("//:rules_bazel/java/java_diff_test.bzl", "updated_golden")

package(default_visibility = ["//visibility:public"])

TESTS = [
Expand All @@ -18,6 +20,19 @@ TESTS = [
"ServiceStubClassComposerTest",
]

UPDATE_GOLDENS_TESTS = [
"BatchingDescriptorComposerTest",
"ComposerTest",
"GrpcServiceCallableFactoryClassComposerTest",
"GrpcServiceStubClassComposerTest",
"MockServiceClassComposerTest",
"MockServiceImplClassComposerTest",
"ResourceNameHelperClassComposerTest",
"ServiceSettingsClassComposerTest",
"ServiceStubSettingsClassComposerTest",
"ServiceStubClassComposerTest",
]

filegroup(
name = "composer_files",
srcs = glob(["*.java"]),
Expand Down Expand Up @@ -69,3 +84,22 @@ java_proto_library(
"@junit_junit//jar",
],
) for test_name in TESTS]



TEST_CLASS_DIR = "com.google.api.generator.gapic.composer."
# Run `bazel run src/test/java/com/google/api/generator/gapic/composer:testTargetName_update`
# to update goldens as expected generated code.
# `ServiceClient*` tests are not supported now since they are still in active development.

[updated_golden(
name = test_name + "_update",
srcs = [
":composer_files",
"//src/test/java/com/google/api/generator/gapic/testdata:gapic_config_files",
"//src/test/java/com/google/api/generator/gapic/testdata:service_config_files",
"//src/test/java/com/google/api/generator/gapic/composer/goldens:goldens_files",
"//src/test/java/com/google/api/generator/test/framework:framework_files",
],
test_class_name = TEST_CLASS_DIR + test_name,
) for test_name in UPDATE_GOLDENS_TESTS]
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.gapic.protoparser.ServiceConfigParser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.logging.v2.LogEntryProto;
import com.google.logging.v2.LoggingConfigProto;
import com.google.logging.v2.LoggingMetricsProto;
Expand Down Expand Up @@ -99,6 +100,8 @@ public void batchingDescriptor_hasSubresponseField() {
method, batchingSetting, messageTypes);

batchingDescriptorExpr.accept(writerVisitor);
Utils.saveCodegenToFile(
this.getClass(), "BatchingDescriptorComposerTestSubresponse.golden", writerVisitor.write());
Path goldenFilePath =
Paths.get(
ComposerConstants.GOLDENFILES_DIRECTORY,
Expand Down Expand Up @@ -155,6 +158,10 @@ public void batchingDescriptor_noSubresponseField() {
method, batchingSetting, messageTypes);

batchingDescriptorExpr.accept(writerVisitor);
Utils.saveCodegenToFile(
this.getClass(),
"BatchingDescriptorComposerTestNoSubresponse.golden",
writerVisitor.write());
Path goldenFilePath =
Paths.get(
ComposerConstants.GOLDENFILES_DIRECTORY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.api.generator.gapic.model.GapicClass;
import com.google.api.generator.gapic.model.GapicClass.Kind;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
Expand All @@ -39,6 +40,7 @@ public void gapicClass_addApacheLicense() {
Composer.addApacheLicense(Arrays.asList(GapicClass.create(Kind.TEST, classDef)));
JavaWriterVisitor visitor = new JavaWriterVisitor();
gapicClassWithHeaderList.get(0).classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "ComposerTest.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "ComposerTest.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "GrpcEchoCallableFactory.golden", visitor.write());
Path goldenFilePath =
Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "GrpcEchoCallableFactory.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "GrpcEchoStub.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "GrpcEchoStub.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "MockEcho.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "MockEcho.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "MockEchoImpl.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "MockEchoImpl.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -97,6 +98,7 @@ public void generateResourceNameClass_echoFoobarMultiplePatterns() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "FoobarName.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "FoobarName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand All @@ -122,6 +124,7 @@ public void generateResourceNameClass_testingSessionOnePattern() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "SessionName.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "SessionName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -60,6 +61,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "EchoSettings.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.api.generator.gapic.model.Service;
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.protobuf.Descriptors.FileDescriptor;
import com.google.protobuf.Descriptors.ServiceDescriptor;
import com.google.showcase.v1beta1.EchoOuterClass;
Expand Down Expand Up @@ -59,6 +60,7 @@ public void generateServiceClasses() {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "EchoStub.golden", visitor.write());
Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoStub.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.api.generator.gapic.protoparser.Parser;
import com.google.api.generator.gapic.protoparser.ServiceConfigParser;
import com.google.api.generator.test.framework.Assert;
import com.google.api.generator.test.framework.Utils;
import com.google.logging.v2.LogEntryProto;
import com.google.logging.v2.LoggingConfigProto;
import com.google.logging.v2.LoggingMetricsProto;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void generateServiceStubSettingsClasses_batchingWithEmptyResponses() thro

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(
this.getClass(), "LoggingServiceV2StubSettings.golden", visitor.write());
Path goldenFilePath =
Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "LoggingServiceV2StubSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
Expand Down Expand Up @@ -135,6 +138,7 @@ public void generateServiceStubSettingsClasses_batchingWithNonemptyResponses()

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "PublisherStubSettings.golden", visitor.write());
Path goldenFilePath =
Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "PublisherStubSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
Expand Down Expand Up @@ -165,6 +169,7 @@ public void generateServiceStubSettingsClasses_basic() throws IOException {

JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "EchoStubSettings.golden", visitor.write());
Path goldenFilePath =
Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "EchoStubSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ public long countBytes(PublishRequest request) {
return request.getSerializedSize();
}

}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intended since the generated Batchingdescriptor code snippet is without new line.