setup-plugin-tests.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  2. ## Copyright 2024, gRPC Authors All rights reserved.
  3. ##
  4. ## Licensed under the Apache License, Version 2.0 (the "License");
  5. ## you may not use this file except in compliance with the License.
  6. ## You may obtain a copy of the License at
  7. ##
  8. ## http://www.apache.org/licenses/LICENSE-2.0
  9. ##
  10. ## Unless required by applicable law or agreed to in writing, software
  11. ## distributed under the License is distributed on an "AS IS" BASIS,
  12. ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. ## See the License for the specific language governing permissions and
  14. ## limitations under the License.
  15. set -euo pipefail
  16. log() { printf -- "** %s\n" "$*" >&2; }
  17. error() { printf -- "** ERROR: %s\n" "$*" >&2; }
  18. fatal() { error "$@"; exit 1; }
  19. output_directory="${PLUGIN_TESTS_OUTPUT_DIRECTORY:=$(mktemp -d)}"
  20. here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  21. grpc_swift_protobuf_directory="$(readlink -f "${here}/..")"
  22. resources_directory="$(readlink -f "${grpc_swift_protobuf_directory}/IntegrationTests/PluginTests/Resources")"
  23. scratch_directory="$(mktemp -d)"
  24. echo "Output directory: $output_directory"
  25. echo "grpc-swift-protobuf directory: $grpc_swift_protobuf_directory"
  26. # modify Package.swift
  27. cp "${resources_directory}/Package.swift" "${scratch_directory}/"
  28. cat >> "${scratch_directory}/Package.swift" <<- EOM
  29. package.dependencies.append(
  30. .package(path: "$grpc_swift_protobuf_directory")
  31. )
  32. EOM
  33. # test_01_top_level_config_file
  34. test_01_output_directory="${output_directory}/test_01_top_level_config_file"
  35. mkdir -p "${test_01_output_directory}/Sources/Protos"
  36. cp "${scratch_directory}/Package.swift" "${test_01_output_directory}/"
  37. cp "${resources_directory}/HelloWorldAdopter.swift" "${test_01_output_directory}/Sources/adopter.swift"
  38. cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_01_output_directory}/Sources/Protos"
  39. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_01_output_directory}/Sources/grpc-swift-proto-generator-config.json"
  40. # test_02_peer_config_file
  41. test_02_output_directory="${output_directory}/test_02_peer_config_file"
  42. mkdir -p "${test_02_output_directory}/Sources/Protos"
  43. cp "${scratch_directory}/Package.swift" "${test_02_output_directory}/"
  44. cp "${resources_directory}/HelloWorldAdopter.swift" "${test_02_output_directory}/Sources/adopter.swift"
  45. cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_02_output_directory}/Sources/Protos/"
  46. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_02_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json"
  47. # test_03_separate_service_message_protos
  48. test_03_output_directory="${output_directory}/test_03_separate_service_message_protos"
  49. mkdir -p "${test_03_output_directory}/Sources/Protos"
  50. cp "${scratch_directory}/Package.swift" "${test_03_output_directory}/"
  51. cp "${resources_directory}/HelloWorldAdopter.swift" "${test_03_output_directory}/Sources/adopter.swift"
  52. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_03_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json"
  53. cp "${resources_directory}/HelloWorld/Service.proto" "${test_03_output_directory}/Sources/Protos/"
  54. cp "${resources_directory}/HelloWorld/Messages.proto" "${test_03_output_directory}/Sources/Protos/"
  55. # test_04_cross_directory_imports
  56. test_04_output_directory="${output_directory}/test_04_cross_directory_imports"
  57. mkdir -p "${test_04_output_directory}/Sources/Protos/directory_1"
  58. mkdir -p "${test_04_output_directory}/Sources/Protos/directory_2"
  59. cp "${scratch_directory}/Package.swift" "${test_04_output_directory}/"
  60. cp "${resources_directory}/HelloWorldAdopter.swift" "${test_04_output_directory}/Sources/adopter.swift"
  61. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_04_output_directory}/Sources/Protos/directory_1/grpc-swift-proto-generator-config.json"
  62. cp "${resources_directory}/import-directory-1-grpc-swift-proto-generator-config.json" "${test_04_output_directory}/Sources/Protos/directory_2/grpc-swift-proto-generator-config.json"
  63. cp "${resources_directory}/HelloWorld/Service.proto" "${test_04_output_directory}/Sources/Protos/directory_2/"
  64. cp "${resources_directory}/HelloWorld/Messages.proto" "${test_04_output_directory}/Sources/Protos/directory_1/"
  65. # test_05_two_definitions
  66. test_05_output_directory="${output_directory}/test_05_two_definitions"
  67. mkdir -p "${test_05_output_directory}/Sources/Protos/HelloWorld"
  68. mkdir -p "${test_05_output_directory}/Sources/Protos/Foo"
  69. cp "${scratch_directory}/Package.swift" "${test_05_output_directory}/"
  70. cp "${resources_directory}/FooHelloWorldAdopter.swift" "${test_05_output_directory}/Sources/adopter.swift"
  71. cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_05_output_directory}/Sources/Protos/HelloWorld/"
  72. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_05_output_directory}/Sources/Protos/grpc-swift-proto-generator-config.json"
  73. cp "${resources_directory}/Foo/foo-messages.proto" "${test_05_output_directory}/Sources/Protos/Foo/"
  74. cp "${resources_directory}/Foo/foo-service.proto" "${test_05_output_directory}/Sources/Protos/Foo/"
  75. # test_06_nested_definitions
  76. test_06_output_directory="${output_directory}/test_06_nested_definitions"
  77. mkdir -p "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo"
  78. cp "${scratch_directory}/Package.swift" "${test_06_output_directory}/"
  79. cp "${resources_directory}/FooHelloWorldAdopter.swift" "${test_06_output_directory}/Sources/adopter.swift"
  80. cp "${resources_directory}/HelloWorld/HelloWorld.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/"
  81. cp "${resources_directory}/internal-grpc-swift-proto-generator-config.json" "${test_06_output_directory}/Sources/Protos/HelloWorld/grpc-swift-proto-generator-config.json"
  82. cp "${resources_directory}/public-grpc-swift-proto-generator-config.json" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/grpc-swift-proto-generator-config.json"
  83. cp "${resources_directory}/Foo/foo-messages.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo/"
  84. cp "${resources_directory}/Foo/foo-service.proto" "${test_06_output_directory}/Sources/Protos/HelloWorld/FooDefinitions/Foo/"