mock_authorization_endpoint.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2021 gRPC authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #ifndef GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H
  15. #define GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H
  16. #include <grpc/support/port_platform.h>
  17. #include "src/core/lib/iomgr/endpoint.h"
  18. namespace grpc_core {
  19. class MockAuthorizationEndpoint : public grpc_endpoint {
  20. public:
  21. MockAuthorizationEndpoint(absl::string_view local_uri,
  22. absl::string_view peer_uri)
  23. : local_address_(local_uri), peer_address_(peer_uri) {
  24. static constexpr grpc_endpoint_vtable vtable = {
  25. nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
  26. nullptr, GetPeer, GetLocalAddress, nullptr, nullptr};
  27. grpc_endpoint::vtable = &vtable;
  28. }
  29. static absl::string_view GetPeer(grpc_endpoint* ep) {
  30. MockAuthorizationEndpoint* m =
  31. reinterpret_cast<MockAuthorizationEndpoint*>(ep);
  32. return m->peer_address_;
  33. }
  34. static absl::string_view GetLocalAddress(grpc_endpoint* ep) {
  35. MockAuthorizationEndpoint* m =
  36. reinterpret_cast<MockAuthorizationEndpoint*>(ep);
  37. return m->local_address_;
  38. }
  39. void SetPeer(absl::string_view peer_address) {
  40. peer_address_ = std::string(peer_address);
  41. }
  42. void SetLocalAddress(absl::string_view local_address) {
  43. local_address_ = std::string(local_address);
  44. }
  45. private:
  46. std::string local_address_;
  47. std::string peer_address_;
  48. };
  49. } // namespace grpc_core
  50. #endif // GRPC_TEST_CORE_UTIL_MOCK_AUTHORIZATION_ENDPOINT_H