TensorFlow Serving C++ API Documentation
status_util_test.cc
1 /* Copyright 2018 Google Inc. All Rights Reserved.
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 ==============================================================================*/
15 
16 #include "tensorflow_serving/util/status_util.h"
17 
18 #include <gtest/gtest.h>
19 
20 namespace tensorflow {
21 namespace serving {
22 namespace {
23 
24 TEST(StatusUtilTest, ConvertsErrorStatusToStatusProto) {
25  Status status =
26  Status(static_cast<absl::StatusCode>(absl::StatusCode::kAborted),
27  "aborted error message");
28  StatusProto status_proto = ToStatusProto(status);
29  EXPECT_EQ(tensorflow::error::ABORTED, status_proto.error_code());
30  EXPECT_EQ("aborted error message", status_proto.error_message());
31 }
32 
33 TEST(StatusUtilTest, ConvertsOkStatusToStatusProto) {
34  Status status;
35  StatusProto status_proto = ToStatusProto(status);
36  EXPECT_EQ(tensorflow::error::OK, status_proto.error_code());
37  EXPECT_EQ("", status_proto.error_message());
38 }
39 
40 TEST(StatusUtilTest, ConvertsErrorStatusProtoToStatus) {
41  StatusProto status_proto;
42  status_proto.set_error_code(tensorflow::error::ALREADY_EXISTS);
43  status_proto.set_error_message("already exists error message");
44  Status status = FromStatusProto(status_proto);
45  EXPECT_EQ(tensorflow::error::ALREADY_EXISTS, status.code());
46  EXPECT_EQ("already exists error message", status.message());
47 }
48 
49 TEST(StatusUtilTest, ConvertsOkStatusProtoToStatus) {
50  StatusProto status_proto;
51  status_proto.set_error_code(tensorflow::error::OK);
52  Status status = FromStatusProto(status_proto);
53  EXPECT_EQ(tensorflow::error::OK, status.code());
54  EXPECT_EQ("", status.message());
55 }
56 
57 } // namespace
58 
59 } // namespace serving
60 } // namespace tensorflow