iceberg-cpp
Loading...
Searching...
No Matches
test_resource.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <filesystem>
23#include <fstream>
24#include <memory>
25#include <sstream>
26#include <string>
27
28#include <nlohmann/json.hpp>
29
30#include "iceberg/json_serde_internal.h"
31#include "iceberg/result.h"
33#include "iceberg/test/test_config.h"
34
35namespace iceberg {
36
38static std::string GetResourcePath(const std::string& file_name) {
39 return std::string(ICEBERG_TEST_RESOURCES) + "/" + file_name;
40}
41
43static Result<std::unique_ptr<TableMetadata>> ReadTableMetadataFromResource(
44 const std::string& file_name) {
45 std::filesystem::path path{GetResourcePath(file_name)};
46 if (!std::filesystem::exists(path)) {
47 return InvalidArgument("File does not exist: {}", path.string());
48 }
49
50 std::ifstream file(path);
51 std::stringstream buffer;
52 buffer << file.rdbuf();
53
54 return TableMetadataFromJson(nlohmann::json::parse(buffer.str()));
55}
56
57} // namespace iceberg