TensorFlow Serving C++ API Documentation
servable_data_test.cc
1 /* Copyright 2016 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/core/servable_data.h"
17 
18 #include <string>
19 
20 #include <gtest/gtest.h>
21 #include "tensorflow/core/lib/core/errors.h"
22 #include "tensorflow/core/lib/core/status_test_util.h"
23 #include "tensorflow/core/platform/types.h"
24 
25 namespace tensorflow {
26 namespace serving {
27 namespace {
28 
29 TEST(ServableDataTest, NoError) {
30  ServableId id = {"name", 42};
31  ServableData<string> data(id, "yo");
32  EXPECT_EQ(id, data.id());
33  TF_EXPECT_OK(data.status());
34  EXPECT_EQ("yo", data.DataOrDie());
35  EXPECT_EQ("yo", data.ConsumeDataOrDie());
36 }
37 
38 TEST(ServableDataTest, StaticCreateNoError) {
39  ServableId id = {"name", 42};
40  auto data = CreateServableData(id, "yo");
41  EXPECT_EQ(id, data.id());
42  TF_EXPECT_OK(data.status());
43  EXPECT_EQ("yo", data.DataOrDie());
44  EXPECT_EQ("yo", data.ConsumeDataOrDie());
45 }
46 
47 TEST(ServableDataTest, Error) {
48  ServableId id = {"name", 42};
49  ServableData<string> data(id, errors::Unknown("d'oh"));
50  EXPECT_EQ(id, data.id());
51  EXPECT_EQ(errors::Unknown("d'oh"), data.status());
52 }
53 
54 } // namespace
55 } // namespace serving
56 } // namespace tensorflow