-
Notifications
You must be signed in to change notification settings - Fork 56
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
chore: add unit tests for utilities.sh
#1948
Conversation
generate_library.sh
utilities.sh
@@ -76,15 +76,15 @@ search_additional_protos() { | |||
|
|||
# get gapic options from .yaml and .json files from proto_path. | |||
get_gapic_opts() { | |||
gapic_config=$(find "${proto_path}" -type f -name "*gapic.yaml") | |||
gapic_config=$(find "$proto_path" -type f -name "*gapic.yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer "${var}" over "$var"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reference, I'll draft another PR to fix formatting issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Tomo for sharing this! This is really helpful, I see a section regarding when to use shell which I think it's worth discussing more in our next meeting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to have another PR for the unit testing of generate_library.sh
?
@@ -76,15 +76,15 @@ search_additional_protos() { | |||
|
|||
# get gapic options from .yaml and .json files from proto_path. | |||
get_gapic_opts() { | |||
gapic_config=$(find "${proto_path}" -type f -name "*gapic.yaml") | |||
gapic_config=$(find "$proto_path" -type f -name "*gapic.yaml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Tomo for sharing this! This is really helpful, I see a section regarding when to use shell which I think it's worth discussing more in our next meeting.
"$gapic_opts" | ||
} | ||
|
||
remove_grpc_version_test() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not directly related to the tests, I wonder why we have to remove the gRPC version manually, what made the differences? Separately, I think it might be good to keep the version for troubleshooting/informational purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using bazel build
, there's a "by gRPC proto compiler" at the beginning of *Grpc.java file. However, the annotation becomes "by gRPC proto compiler xxx" when using shell script, where xxx is the grpc version.
I use this function to remove the version number so that two files are totally identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought bazel build
eventually calls the same gRPC proto compiler? If not, we need to understand what exactly caused the differences, as there could be more differences when generating other services.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bazel build
download the gRPC proto compiler source code from github (defined here in gax/repository.bzl) and build from source.
In generate_library.sh
, it download gPRC compiler executable from maven central. I don't know whether there are differences but the generated code are the same.
I haven't seen any code difference when generating other services and I'll add more libraries to the integration test to make sure the generated code is the same as bazel build
.
I also post a question and hope someone from grpc team has the answer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think bazel build download the gRPC proto compiler source code from github (defined here in gax/repository.bzl) and build from source.
Thanks, this makes sense! Since we were building from source, maybe there is no concept of version
on main branch, let's see if anyone answers the question.
I think |
Unit tests and Integration tests serve different purposes. Integration tests treat the script somewhat like a black box and make sure it works in a real life scenario. Unit tests treat the script as a white box and attempt to test every combinations with test data. |
|
||
# Helper functions, they shouldn't be called outside this file. | ||
__assertEquals() { | ||
expected=$1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go/shell-style#use-local-variables
Functions should declare their local variables with the local
keyword. We have several functions (not only in this PR) around that are not following this style. cc: @blakeli0 @suztomo would it make sense to have a "styling up" PR to make our scripts more compliant with the guidelines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go/shell-style#constants-environment-variables-and-readonly-variables
Another example, to have constants with upper case (e.g. SCRIPT_DIR
instead of script_dir
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvm, I saw at the end of the changes we have https://github.com/googleapis/sdk-platform-java/pull/1948/files#r1311724425 to address this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I plan to propose a PR to format code after merging this one.
download_generator_success_with_valid_version_test() { | ||
download_generator "2.24.0" | ||
__assertFileExists "gapic-generator-java-2.24.0.jar" | ||
rm "gapic-generator-java-2.24.0.jar" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can have an "afterEach
" function that cleans up the downloaded jars/tars, even if they don't exist. It could even be useful for local development where I personally find it a bit hard to read dir contents after I call the scripts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be expanded with a git status
to confirm we don't have any unexpected untracked files that aren't deleted by such function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all tests have clean up actions so it's difficult to write a function and apply it after every test execution.
However, I'll think about it in the reformat PR.
Unit test should test against public APIs so I think we can test |
[gapic-generator-java-root] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_integration_tests] Kudos, SonarCloud Quality Gate passed! |
[java_showcase_unit_tests] Kudos, SonarCloud Quality Gate passed! |
SGTM!
I like the idea, this is similar to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the content of these test files matter? If not or only partially matters, can we simplify the content to only what we need? In addition, it would be great if we can name these test files based on what we are testing, and/or add additional comments on each yaml to indicate what this testing yaml is for. e.g. Something like This yaml is only intended for testing search_additional_protos function
with a yaml name search_additional_protos_scenario_xyz.yaml
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense.
I'll change the name and contents of yaml files in the reformat PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending a question regarding the testing files. There are a few additional follow ups that need to be done(unit tests and golden tests for generate_library.sh
, style change etc), but they don't have to completed as part of this PR.
Fixes #1947 ☕️
The list of utility functions:
Functions with star (*) are tested in this PR.