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

Removing maxdepth option to find #296

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions all/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ printUsage() {
echo " --go-package-map Map proto imports to go import paths"
echo " --go-plugin-micro Replaces the Go gRPC plugin with go-micro"
echo " --go-proto-validator Generate Go proto validations - see https://github.com/mwitkow/go-proto-validators"
echo " --go-full-directory-depth When using -d allow full depth search for proto files, otherwise shallow depth is used (maxdepth of 1)"
echo " --no-google-includes Don't include Google protobufs"
echo " --descr-include-imports When using --descriptor_set_out, also include all dependencies of the input files in the set, so that the set is self-contained"
echo " --descr-include-source-info When using --descriptor_set_out, do not strip SourceCodeInfo from the FileDescriptorProto. This results in vastly
Expand Down Expand Up @@ -58,6 +59,7 @@ GO_MODULE_PREFIX=""
GO_PACKAGE_MAP=""
GO_PLUGIN="grpc"
GO_VALIDATOR=false
GO_FULL_DIRECTORY_DEPTH=false
NO_GOOGLE_INCLUDES=false
DESCR_INCLUDE_IMPORTS=false
DESCR_INCLUDE_SOURCE_INFO=false
Expand Down Expand Up @@ -173,6 +175,10 @@ while test $# -gt 0; do
GO_VALIDATOR=true
shift
;;
--go-full-directory-depth)
GO_FULL_DIRECTORY_DEPTH=true
shift
;;
--no-google-includes)
NO_GOOGLE_INCLUDES=true
shift
Expand Down Expand Up @@ -432,10 +438,10 @@ PROTO_INCLUDE="$PROTO_INCLUDE $EXTRA_INCLUDES"
if [ ! -z $PROTO_DIR ]; then
PROTO_INCLUDE="$PROTO_INCLUDE -I $PROTO_DIR"
FIND_DEPTH=""
if [[ $GEN_LANG == "go" ]]; then
if [[ $GEN_LANG == "go" && $GO_FULL_DIRECTORY_DEPTH == false ]]; then
FIND_DEPTH="-maxdepth 1"
fi
PROTO_FILES=(`find ${PROTO_DIR} ${FIND_DEPTH} -name "*.proto"`)
fi
PROTO_FILES=$(find "${PROTO_DIR}" ${FIND_DEPTH} -name "*.proto")
else
PROTO_INCLUDE="-I . $PROTO_INCLUDE"
PROTO_FILES=($FILE)
Expand Down
78 changes: 52 additions & 26 deletions all/test.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash -efx

LANGS=("go" "ruby" "csharp" "java" "python" "objc" "node" "gogo" "php" "cpp" "descriptor_set" "web")

CONTAINER=${CONTAINER}
Expand All @@ -19,19 +18,26 @@ testGeneration() {
shift
lang=$1
shift
withdir=$1
shift
expected_output_dir=$1
shift
expectedExitCode=$1
shift
extra_args=$@

file_directive="-f all/test/test.proto"
if [[ "$withdir" == 'true' ]]; then
file_directive="-d all/test"
fi

mkdir -p "$name" > /dev/null 2>&1
cp -r ./all "./$name" > /dev/null 2>&1
pushd "./$name" > /dev/null

# Test calling a file directly.
exitCode=0
docker run --rm -v="$PWD":/defs "$CONTAINER" -f all/test/test.proto -l "$lang" -i all/test/ $extra_args > /dev/null || exitCode=$?
docker run --rm -v="$PWD":/defs "$CONTAINER" $file_directive -l "$lang" -i all/ $extra_args > /dev/null || exitCode=$?

if [[ $expectedExitCode != $exitCode ]]; then
echo >&2 "[Fail] $name"
Expand Down Expand Up @@ -303,64 +309,64 @@ testGeneration() {
}

# Test docs generation
testGeneration "go_with_docs" go "gen/pb-go" 0 --with-docs
testGeneration "go_with_markdown_docs" go "gen/pb-go" 0 --with-docs markdown,index.md
testGeneration "go_with_docs" go "false" "gen/pb-go" 0 --with-docs
testGeneration "go_with_markdown_docs" go "false" "gen/pb-go" 0 --with-docs markdown,index.md

# Test grpc-gateway generation (only valid for Go)
testGeneration "go_with_gateway" go "gen/pb-go" 0 --with-gateway
testGeneration "go_with_gateway" go "false" "gen/pb-go" 0 --with-gateway

# Test grpc-gateway generation + json (only valid for Go)
testGeneration "go_with_gateway_and_openapi_json" go "gen/pb-go" 0 --with-gateway --with-openapi-json-names
testGeneration "go_with_gateway_and_openapi_json" go "false" "gen/pb-go" 0 --with-gateway --with-openapi-json-names

# Test grpc-gateway generation + json (deprecated) (only valid for Go)
testGeneration "go_with_gateway_and_swagger_json" go "gen/pb-go" 0 --with-gateway --with-swagger-json-names
testGeneration "go_with_gateway_and_swagger_json" go "false" "gen/pb-go" 0 --with-gateway --with-swagger-json-names

# Test grpc-gateway generation with unbound methods (only valid for Go)
testGeneration "go_with_unbound_methods" go "gen/pb-go" 0 --with-gateway --generate-unbound-methods
testGeneration "go_with_unbound_methods" go "false" "gen/pb-go" 0 --with-gateway --generate-unbound-methods

# Test go source relative generation
testGeneration "go_with_source_relative" go "gen/pb-go" 0 --go-source-relative
testGeneration "go_with_source_relative" go "false" "gen/pb-go" 0 --go-source-relative

# Test go module prefix
testGeneration "go_with_module_prefixes" go "gen/pb-go" 0 --go-module-prefix all
testGeneration "go_with_module_prefixes" go "false" "gen/pb-go" 0 --go-module-prefix all

# Test expected failure for source relative and module prefix combination
testGeneration "go_with_module_prefixes_and_source_relative" go "gen/pb-go" 1 --go-module-prefix all --go-source-relative
testGeneration "go_with_module_prefixes_and_source_relative_swapped_args" go "gen/pb-go" 1 --go-source-relative --go-module-prefix all
testGeneration "go_with_module_prefixes_and_source_relative" go "false" "gen/pb-go" 1 --go-module-prefix all --go-source-relative
testGeneration "go_with_module_prefixes_and_source_relative_swapped_args" go "false" "gen/pb-go" 1 --go-source-relative --go-module-prefix all

# Test go validator
testGeneration "go_with_validator" go "gen/pb-go" 0 --with-validator
testGeneration "go_with_validator" go "false" "gen/pb-go" 0 --with-validator

# Test go validator with source relative option
testGeneration "go_with_validator_and_source_relative" go "gen/pb-go" 0 --with-validator --validator-source-relative
testGeneration "go_with_validator_and_source_relative" go "false" "gen/pb-go" 0 --with-validator --validator-source-relative

# Test the other go validator
testGeneration "go_with_proto_validator" go "gen/pb-go" 0 --go-proto-validator
testGeneration "go_with_proto_validator" go "false" "gen/pb-go" 0 --go-proto-validator

# Test the other go validator with source relative option
testGeneration "go_with_proto_validator_and_source_relative" go "gen/pb-go" 0 ---go-proto-validator --validator-source-relative
testGeneration "go_with_proto_validator_and_source_relative" go "false" "gen/pb-go" 0 ---go-proto-validator --validator-source-relative

# Test go-micro generations
testGeneration "go_micro" go "gen/pb-go" 0 --go-plugin-micro
testGeneration "go_micro" go "false" "gen/pb-go" 0 --go-plugin-micro

# Test Sorbet RBI declaration file generation (only valid for Ruby)
testGeneration "ruby_rbi" ruby "gen/pb-ruby" 0 --with-rbi
testGeneration "ruby_rbi" ruby "false" "gen/pb-ruby" 0 --with-rbi

# Test TypeScript declaration file generation (only valid for Node)
testGeneration "node_with_typescript" node "gen/pb-node" 0 --with-typescript
testGeneration "node_with_typescript" node "false" "gen/pb-node" 0 --with-typescript

# Test node alternative import style (only valid for node and web)
testGeneration "node_with_alternative_imports" node "gen/pb-node" 0 --js-out library=testlib
testGeneration "node_with_alternative_imports" node "false" "gen/pb-node" 0 --js-out library=testlib

# Test node grpc-out alternative import style (only valid for node and web)
testGeneration "node_with_grpc_out" node "gen/pb-node" 0 --grpc-out grpc-js
testGeneration "node_with_grpc_out" node "false" "gen/pb-node" 0 --grpc-out grpc-js

# Test grpc web alternative import style (only valid for web)
testGeneration "web_with_typescript_imports" web "gen/pb-web" 0 --grpc-web-out import_style=typescript
testGeneration "web_with_commonjs_imports" web "gen/pb-web" 0 --grpc-web-out import_style=commonjs+dts
testGeneration "web_with_typescript_imports" web "false" "gen/pb-web" 0 --grpc-web-out import_style=typescript
testGeneration "web_with_commonjs_imports" web "false" "gen/pb-web" 0 --grpc-web-out import_style=commonjs+dts

# Test java output
testGeneration "java_test_jar" java "gen" 0 -o gen/test.jar
testGeneration "java_test_jar" java "false" "gen" 0 -o gen/test.jar

# Test java output
testGeneration "java_with_validator" java "gen/pb-java" 0 --with-validator
Expand All @@ -375,9 +381,29 @@ for lang in ${LANGS[@]}; do
fi

# Test without an output directory.
testGeneration "$lang" "$lang" "$expected_output_dir" 0
testGeneration "$lang" "$lang" "false" "$expected_output_dir" 0

# Test with an output directory.
test_dir="gen/foo/bar"
testGeneration "${lang}_with_output_dir" "$lang" "$test_dir" 0 -o "$test_dir"
testGeneration "${lang}_with_output_dir" "$lang" "false" "$test_dir" 0 -o "$test_dir"
done

#Generate proto files but using the -d switch to just pass a directory input
for lang in ${LANGS[@]}; do
Copy link
Contributor

Choose a reason for hiding this comment

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

mind refactoring this a little bit and use the same loop to test all withdir true/false cases?

expected_output_dir=""
if [[ "$lang" == "python" ]]; then
expected_output_dir="gen/pb_$lang"
else
expected_output_dir="gen/pb-$lang"
fi

# Test without an output directory.
testGeneration "$lang" "$lang" "false" "$expected_output_dir" 0

# Test with an output directory.
test_dir="gen/foo/bar"
testGeneration "${lang}_from_dir_with_output_dir" "$lang" "true" "$test_dir" 0 -o "$test_dir"
done

#Test the -d for go but also add the the "--go-full-directory-depth" which removes the shallow find flag
testGeneration "go_full_depth_search" "go" "true" "gen/pb-go" 0 "--go-full-directory-depth"
Copy link
Contributor

Choose a reason for hiding this comment

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

  • I think that for this test we should have multiple proto files in different directory depths and verify that they are all generated, and also that those files are NOT generated when the flag is not used.
  • If you don't mind also moving this test to where the other go specific tests are?

2 changes: 1 addition & 1 deletion all/test/test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ syntax = "proto3";

package Messages;

import "all/test/include.proto";
import "test/include.proto";
import "google/api/annotations.proto";
import "google/protobuf/field_mask.proto";
import "validate/validate.proto";
Expand Down