resolv_gold_test: assert if parse the .pbtxt files failed

Test: atest
Change-Id: I851e9c886cb2a2e50e32be56cdcbd95c01d47067
diff --git a/tests/resolv_gold_test.cpp b/tests/resolv_gold_test.cpp
index 5216268..3d7235f 100644
--- a/tests/resolv_gold_test.cpp
+++ b/tests/resolv_gold_test.cpp
@@ -20,6 +20,7 @@
 #include <Fwmark.h>
 #include <android-base/chrono_utils.h>
 #include <android-base/file.h>
+#include <android-base/result.h>
 #include <android-base/stringprintf.h>
 #include <gmock/gmock-matchers.h>
 #include <google/protobuf/text_format.h>
@@ -38,6 +39,7 @@
 
 namespace android::net {
 
+using android::base::Result;
 using android::base::StringPrintf;
 using android::netdutils::ScopedAddrinfo;
 using std::chrono::milliseconds;
@@ -123,14 +125,18 @@
         return false;
     }
 
-    GoldTest ToProto(const std::string& file) {
+    Result<GoldTest> ToProto(const std::string& filename) {
         // Convert the testing configuration from .pbtxt file to proto.
-        std::string file_content;
-        const std::string file_name = kTestDataPath + file;
-        EXPECT_TRUE(android::base::ReadFileToString(file_name, &file_content))
-                << "Failed to read " << file_name << ": " << strerror(errno);
+        std::string content;
+        const std::string path = kTestDataPath + filename;
+
+        bool ret = android::base::ReadFileToString(path, &content);
+        if (!ret) return Errorf("Read {} failed: {}", path, strerror(errno));
+
         android::net::GoldTest goldtest;
-        EXPECT_TRUE(google::protobuf::TextFormat::ParseFromString(file_content, &goldtest));
+        ret = google::protobuf::TextFormat::ParseFromString(content, &goldtest);
+        if (!ret) return Errorf("Parse {} failed", path);
+
         return goldtest;
     }
 
@@ -417,7 +423,9 @@
     }
 
     // Read test configuration from proto text file to proto.
-    const auto goldtest = ToProto(file);
+    const Result<GoldTest> result = ToProto(file);
+    ASSERT_TRUE(result.ok()) << result.error().message();
+    const GoldTest& goldtest = result.value();
 
     // Register packet mappings (query, response) from proto.
     SetupMappings(goldtest, dns);