Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: api server write json #3366

Merged
merged 3 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/apiserver/api_server_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -942,12 +942,12 @@
case hybridse::sdk::kTypeBool: {
bool value = false;
rs->GetBool(i, &value);
ar&(value ? "true" : "false");
ar& value;

Check warning on line 945 in src/apiserver/api_server_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_impl.cc#L945

Added line #L945 was not covered by tests
break;
}
default: {
LOG(ERROR) << "Invalid Column Type";
ar & "NA";
ar& std::string("NA");

Check warning on line 950 in src/apiserver/api_server_impl.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_impl.cc#L950

Added line #L950 was not covered by tests
break;
}
}
Expand Down
60 changes: 60 additions & 0 deletions src/apiserver/api_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,66 @@
ASSERT_TRUE(env->cluster_remote->ExecuteDDL(env->db, "drop table trans;", &status));
}

TEST_F(APIServerTest, testResultType) {

Check warning on line 684 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L684

Added line #L684 was not covered by tests
// check about json write
const auto env = APIServerTestEnv::Instance();

Check warning on line 686 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L686

Added line #L686 was not covered by tests
// don't need table data
std::string ddl =
"create table if not exists multi_type(c1 bool, c2 smallint, c3 int, c4 bigint, c5 float, c6 double, c7 "
"string, c8 date, c9 timestamp, c10_str string);";
hybridse::sdk::Status status;

Check warning on line 691 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L690-L691

Added lines #L690 - L691 were not covered by tests

env->cluster_remote->ExecuteSQL(env->db, ddl, &status);
ASSERT_TRUE(status.IsOK()) << status.msg;
ASSERT_TRUE(env->cluster_sdk->Refresh());
std::string deploy = "deploy d1 select c1, c2, c3, c4, c5, c6, c7, c8, c9, c10_str from multi_type;";
env->cluster_remote->ExecuteSQL(env->db, deploy, &status);
ASSERT_TRUE(status.IsOK()) << status.msg;
ASSERT_TRUE(env->cluster_sdk->Refresh());

Check warning on line 699 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L693-L699

Added lines #L693 - L699 were not covered by tests

{
brpc::Controller cntl;
cntl.http_request().set_method(brpc::HTTP_METHOD_POST);
cntl.http_request().uri() = "http://127.0.0.1:8010/dbs/" + env->db + "/deployments/" + "d1";
cntl.request_attachment().append(R"({

Check warning on line 705 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L702-L705

Added lines #L702 - L705 were not covered by tests
"input":
[
[ true,32767,65535,9223372036854775807,1.1,2.2,"abc","2021-12-01",11111111111111,"def" ],
[ false,32767,65535,null,1.1,2.2,"abc",null,null,"def" ]
]
})"); // null must be lower case
env->http_channel.CallMethod(NULL, &cntl, NULL, NULL, NULL);
ASSERT_FALSE(cntl.Failed()) << cntl.ErrorText();

Check warning on line 713 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L712-L713

Added lines #L712 - L713 were not covered by tests

LOG(INFO) << "exec deployment resp:\n" << cntl.response_attachment().to_string();
butil::rapidjson::Document document;

Check warning on line 716 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L715-L716

Added lines #L715 - L716 were not covered by tests
// check resp data
if (document.Parse(cntl.response_attachment().to_string().c_str()).HasParseError()) {
ASSERT_TRUE(false) << "response parse failed with code " << document.GetParseError()
<< ", raw resp: " << cntl.response_attachment().to_string();

Check warning on line 720 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L718-L720

Added lines #L718 - L720 were not covered by tests
}
ASSERT_EQ(0, document["code"].GetInt());
ASSERT_STREQ("ok", document["msg"].GetString());
ASSERT_TRUE(document["data"].FindMember("schema") == document["data"].MemberEnd());
ASSERT_EQ(2, document["data"]["data"].Size());
ASSERT_EQ(0, document["data"]["common_cols_data"].Size());

Check warning on line 726 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L722-L726

Added lines #L722 - L726 were not covered by tests

// check data.data 2 results
auto& data = document["data"]["data"];
ASSERT_TRUE(data[0].IsArray());
ASSERT_TRUE(data[0][0].GetBool());
ASSERT_EQ(data[0][2].GetInt(), 65535);
ASSERT_STREQ(data[0][7].GetString(), "2021-12-1");

Check warning on line 733 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L729-L733

Added lines #L729 - L733 were not covered by tests

ASSERT_TRUE(data[1].IsArray());
ASSERT_FALSE(data[1][0].GetBool());
ASSERT_TRUE(data[1][3].IsNull());

Check warning on line 737 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L735-L737

Added lines #L735 - L737 were not covered by tests
}

env->cluster_remote->ExecuteSQL(env->db, "drop deployment d1", &status);
ASSERT_TRUE(status.IsOK()) << status.msg;

Check warning on line 741 in src/apiserver/api_server_test.cc

View check run for this annotation

Codecov / codecov/patch

src/apiserver/api_server_test.cc#L740-L741

Added lines #L740 - L741 were not covered by tests
}

TEST_F(APIServerTest, no_common) {
const auto env = APIServerTestEnv::Instance();

Expand Down
Loading