kythe.io@v0.0.68-0.20240422202219-7225dbc01741/kythe/cxx/common/net_client_test.cc (about)

     1  /*
     2   * Copyright 2015 The Kythe 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   */
    16  
    17  #include "kythe/cxx/common/net_client.h"
    18  
    19  #include <memory>
    20  #include <string>
    21  
    22  #include "absl/flags/flag.h"
    23  #include "absl/flags/parse.h"
    24  #include "absl/log/check.h"
    25  #include "absl/log/initialize.h"
    26  #include "google/protobuf/stubs/common.h"
    27  #include "kythe/proto/common.pb.h"
    28  #include "kythe/proto/graph.pb.h"
    29  
    30  ABSL_FLAG(std::string, xrefs, "http://localhost:8080",
    31            "Base URI for xrefs service");
    32  
    33  namespace {
    34  void TestNodeRequest() {
    35    kythe::XrefsJsonClient client(std::make_unique<kythe::JsonClient>(),
    36                                  absl::GetFlag(FLAGS_xrefs));
    37    kythe::proto::NodesRequest request;
    38    kythe::proto::NodesReply response;
    39    // TODO(zarko): Use kythe::URI once it's merged in.
    40    request.add_ticket("kythe:?lang=c%2B%2B#SOMEFILE");
    41    std::string error;
    42    CHECK(client.Nodes(request, &response, &error)) << error;
    43    CHECK_EQ(1, response.nodes().size()) << response;
    44  
    45    CHECK_EQ(request.ticket(0), response.nodes().begin()->first) << response;
    46    kythe::proto::common::NodeInfo node = response.nodes().begin()->second;
    47    CHECK_EQ(1, node.facts().size()) << response;
    48  
    49    CHECK_EQ("/kythe/node/kind", node.facts().begin()->first);
    50    CHECK_EQ("file", node.facts().begin()->second);
    51  }
    52  }  // namespace
    53  
    54  int main(int argc, char** argv) {
    55    GOOGLE_PROTOBUF_VERIFY_VERSION;
    56    absl::InitializeLog();
    57    absl::ParseCommandLine(argc, argv);
    58    kythe::JsonClient::InitNetwork();
    59    TestNodeRequest();
    60    return 0;
    61  }