| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- #!/bin/bash
- ## Copyright 2024, gRPC Authors All rights reserved.
- ##
- ## Licensed under the Apache License, Version 2.0 (the "License");
- ## you may not use this file except in compliance with the License.
- ## You may obtain a copy of the License at
- ##
- ## http://www.apache.org/licenses/LICENSE-2.0
- ##
- ## Unless required by applicable law or agreed to in writing, software
- ## distributed under the License is distributed on an "AS IS" BASIS,
- ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ## See the License for the specific language governing permissions and
- ## limitations under the License.
- set -euo pipefail
- log() { printf -- "** %s\n" "$*" >&2; }
- error() { printf -- "** ERROR: %s\n" "$*" >&2; }
- fatal() { error "$@"; exit 1; }
- output_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d)}"
- here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
- grpc_swift_protobuf_directory="$(readlink -f "${here}/..")"
- resources_directory="$(readlink -f "${grpc_swift_protobuf_directory}/IntegrationTests/PluginTests/Resources")"
- config="${resources_directory}/Config"
- sources="${resources_directory}/Sources"
- protos="${resources_directory}/Protos"
- scratch_directory="$(mktemp -d)"
- package_manifest="${scratch_directory}/Package.swift"
- echo "Output directory: $output_directory"
- echo "grpc-swift-protobuf directory: $grpc_swift_protobuf_directory"
- # modify Package.swift
- cp "${resources_directory}/Sources/Package.swift" "${scratch_directory}/"
- cat >> "${package_manifest}" <<- EOM
- package.dependencies.append(
- .package(path: "$grpc_swift_protobuf_directory")
- )
- EOM
- function test_dir_name {
- # $FUNCNAME is a stack of function names. The 0th element is the name of this
- # function, so the 1st element is the calling function.
- echo "${output_directory}/${FUNCNAME[1]}"
- }
- function test_01_top_level_config_file {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── HelloWorldAdopter.swift
- # ├── Protos
- # │ └── HelloWorld.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/HelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${protos}/HelloWorld/HelloWorld.proto" "${test_dir}/Sources/Protos"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/grpc-swift-proto-generator-config.json"
- }
- function test_02_peer_config_file {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── HelloWorldAdopter.swift
- # └── Protos
- # ├── HelloWorld.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/HelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${protos}/HelloWorld/HelloWorld.proto" "${test_dir}/Sources/Protos/"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/grpc-swift-proto-generator-config.json"
- }
- function test_03_separate_service_message_protos {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── HelloWorldAdopter.swift
- # └── Protos
- # ├── Messages.proto
- # ├── Service.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/HelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/grpc-swift-proto-generator-config.json"
- cp "${protos}/HelloWorld/Service.proto" "${test_dir}/Sources/Protos/"
- cp "${protos}/HelloWorld/Messages.proto" "${test_dir}/Sources/Protos/"
- }
- function test_04_cross_directory_imports {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── HelloWorldAdopter.swift
- # └── Protos
- # ├── directory_1
- # │ ├── Messages.proto
- # │ └── grpc-swift-proto-generator-config.json
- # └── directory_2
- # ├── Service.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos/directory_1"
- mkdir -p "${test_dir}/Sources/Protos/directory_2"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/HelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json"
- cp "${config}/import-directory-1-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json"
- cp "${protos}/HelloWorld/Service.proto" "${test_dir}/Sources/Protos/directory_2/"
- cp "${protos}/HelloWorld/Messages.proto" "${test_dir}/Sources/Protos/directory_1/"
- }
- function test_05_two_definitions {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── FooHelloWorldAdopter.swift
- # └── Protos
- # ├── Foo
- # │ ├── foo-messages.proto
- # │ └── foo-service.proto
- # ├── HelloWorld
- # │ └── HelloWorld.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos/HelloWorld"
- mkdir -p "${test_dir}/Sources/Protos/Foo"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/FooHelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${protos}/HelloWorld/HelloWorld.proto" "${test_dir}/Sources/Protos/HelloWorld/"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/grpc-swift-proto-generator-config.json"
- cp "${protos}/Foo/foo-messages.proto" "${test_dir}/Sources/Protos/Foo/"
- cp "${protos}/Foo/foo-service.proto" "${test_dir}/Sources/Protos/Foo/"
- }
- function test_06_nested_definitions {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── FooHelloWorldAdopter.swift
- # └── Protos
- # └── HelloWorld
- # ├── FooDefinitions
- # │ ├── Foo
- # │ │ ├── foo-messages.proto
- # │ │ └── foo-service.proto
- # │ └── grpc-swift-proto-generator-config.json
- # ├── HelloWorld.proto
- # └── grpc-swift-proto-generator-config.json
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos/HelloWorld/FooDefinitions/Foo"
- cp "${package_manifest}" "${test_dir}/"
- cp "${sources}/FooHelloWorldAdopter.swift" "${test_dir}/Sources/"
- cp "${protos}/HelloWorld/HelloWorld.proto" "${test_dir}/Sources/Protos/HelloWorld/"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json"
- cp "${config}/public-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json"
- cp "${protos}/Foo/foo-messages.proto" "${test_dir}/Sources/Protos/HelloWorld/FooDefinitions/Foo/"
- cp "${protos}/Foo/foo-service.proto" "${test_dir}/Sources/Protos/HelloWorld/FooDefinitions/Foo/"
- }
- function test_07_duplicated_proto_file_name {
- # .
- # ├── Package.swift
- # └── Sources
- # ├── NoOp.swift
- # └── Protos
- # ├── grpc-swift-proto-generator-config.json
- # ├── noop
- # │ └── noop.proto
- # └── noop2
- # └── noop.proto
- local -r test_dir=$(test_dir_name)
- mkdir -p "${test_dir}/Sources/Protos"
- cp "${package_manifest}" "${test_dir}/"
- mkdir -p "${test_dir}/Sources/Protos"
- cp -rp "${protos}/noop" "${test_dir}/Sources/Protos"
- cp -rp "${protos}/noop2" "${test_dir}/Sources/Protos"
- cp "${sources}/NoOp.swift" "${test_dir}/Sources"
- cp "${config}/internal-grpc-swift-proto-generator-config.json" "${test_dir}/Sources/Protos/grpc-swift-proto-generator-config.json"
- }
- test_01_top_level_config_file
- test_02_peer_config_file
- test_03_separate_service_message_protos
- test_04_cross_directory_imports
- test_05_two_definitions
- test_06_nested_definitions
- test_07_duplicated_proto_file_name
|