Skip to content

Commit

Permalink
Added another test
Browse files Browse the repository at this point in the history
  • Loading branch information
obelisk committed Apr 25, 2018
1 parent 87b3402 commit f375deb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 3 additions & 3 deletions osquery/core/conversions.cpp
Expand Up @@ -235,11 +235,11 @@ Status JSON::fromString(const std::string& str) {
if (!pr) {
std::string message{"Cannot parse JSON: "};
message += GetParseError_En(pr.Code());
message += "Offset: ";
message += pr.Offset();
message += " Offset: ";
message += std::to_string(pr.Offset());
return Status(1, message);
}
return Status{0};
return Status();
}

void JSON::mergeObject(rj::Value& target_obj, rj::Value& source_obj) {
Expand Down
8 changes: 8 additions & 0 deletions osquery/core/tests/conversions_tests.cpp
Expand Up @@ -156,6 +156,14 @@ TEST_F(ConversionsTests, test_json_from_string) {
EXPECT_FALSE(doc.fromString(json).ok());
}

TEST_F(ConversionsTests, test_json_from_string_error) {
std::string json = "{\"key\":\"value\",\"key2\":{\"key3\":'error'}}";
auto doc = JSON::newObject();
auto s = doc.fromString(json);
EXPECT_FALSE(s.ok());
EXPECT_EQ(s.getMessage(), "Cannot parse JSON: Invalid value. Offset: 30");
}

TEST_F(ConversionsTests, test_json_add_object) {
std::string json = "{\"key\":\"value\", \"key2\":{\"key3\":[3,2,1]}}";
auto doc = JSON::newObject();
Expand Down

0 comments on commit f375deb

Please sign in to comment.