This repository has been archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: copy IsProtoEqual from spanner (#179)
Create a new library to host common testing utilities that depend on Protobuf, as the GCS library does not depend on protobuf and we do not want to depend on protobuf for its tests.
- Loading branch information
Showing
8 changed files
with
253 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
google/cloud/testing_util/google_cloud_cpp_testing_grpc.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# 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. | ||
# | ||
# DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed | ||
|
||
"""Automatically generated source lists for google_cloud_cpp_testing_grpc - DO NOT EDIT.""" | ||
|
||
google_cloud_cpp_testing_grpc_hdrs = [ | ||
"is_proto_equal.h", | ||
] | ||
|
||
google_cloud_cpp_testing_grpc_srcs = [ | ||
"is_proto_equal.cc", | ||
] |
21 changes: 21 additions & 0 deletions
21
google/cloud/testing_util/google_cloud_cpp_testing_grpc_unit_tests.bzl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# 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. | ||
# | ||
# DO NOT EDIT -- GENERATED BY CMake -- Change the CMakeLists.txt file if needed | ||
|
||
"""Automatically generated unit tests list - DO NOT EDIT.""" | ||
|
||
google_cloud_cpp_testing_grpc_unit_tests = [ | ||
"is_proto_equal_test.cc", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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. | ||
|
||
#include "google/cloud/testing_util/is_proto_equal.h" | ||
#include <google/protobuf/util/message_differencer.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
inline namespace GOOGLE_CLOUD_CPP_NS { | ||
namespace testing_util { | ||
|
||
optional<std::string> CompareProtos(google::protobuf::Message const& arg, | ||
google::protobuf::Message const& value) { | ||
std::string delta; | ||
google::protobuf::util::MessageDifferencer differencer; | ||
differencer.ReportDifferencesToString(&delta); | ||
auto const result = differencer.Compare(arg, value); | ||
if (result) return {}; | ||
return delta; | ||
} | ||
|
||
} // namespace testing_util | ||
} // namespace GOOGLE_CLOUD_CPP_NS | ||
} // namespace cloud | ||
} // namespace google |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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. | ||
|
||
#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TESTING_UTIL_IS_PROTO_EQUAL_H | ||
#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TESTING_UTIL_IS_PROTO_EQUAL_H | ||
|
||
#include "google/cloud/optional.h" | ||
#include "google/cloud/version.h" | ||
#include <google/protobuf/message.h> | ||
#include <gmock/gmock.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
inline namespace GOOGLE_CLOUD_CPP_NS { | ||
namespace testing_util { | ||
|
||
optional<std::string> CompareProtos(google::protobuf::Message const& arg, | ||
google::protobuf::Message const& value); | ||
|
||
MATCHER_P(IsProtoEqual, value, "Checks whether protos are equal") { | ||
optional<std::string> delta = CompareProtos(arg, value); | ||
if (delta.has_value()) { | ||
*result_listener << "\n" << *delta; | ||
} | ||
return !delta.has_value(); | ||
} | ||
|
||
} // namespace testing_util | ||
} // namespace GOOGLE_CLOUD_CPP_NS | ||
} // namespace cloud | ||
} // namespace google | ||
|
||
#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_TESTING_UTIL_IS_PROTO_EQUAL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2020 Google LLC | ||
// | ||
// 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. | ||
|
||
#include "google/cloud/testing_util/is_proto_equal.h" | ||
#include <google/protobuf/wrappers.pb.h> | ||
#include <gmock/gmock.h> | ||
|
||
namespace google { | ||
namespace cloud { | ||
inline namespace GOOGLE_CLOUD_CPP_NS { | ||
namespace testing_util { | ||
namespace { | ||
|
||
using ::testing::Not; | ||
|
||
TEST(IsProtoEqual, Basic) { | ||
::google::protobuf::StringValue actual; | ||
actual.set_value("Hello World"); | ||
::google::protobuf::StringValue not_actual; | ||
|
||
EXPECT_THAT(actual, IsProtoEqual(actual)); | ||
EXPECT_THAT(actual, Not(IsProtoEqual(not_actual))); | ||
} | ||
|
||
} // namespace | ||
} // namespace testing_util | ||
} // namespace GOOGLE_CLOUD_CPP_NS | ||
} // namespace cloud | ||
} // namespace google |