iceberg_integration_tests/lib.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::collections::HashMap;
19use std::sync::OnceLock;
20
21use iceberg::io::{S3_ACCESS_KEY_ID, S3_ENDPOINT, S3_REGION, S3_SECRET_ACCESS_KEY};
22use iceberg_catalog_rest::REST_CATALOG_PROP_URI;
23use iceberg_test_utils::{get_minio_endpoint, get_rest_catalog_endpoint, set_up};
24
25/// Global test fixture that uses environment-based configuration.
26/// This assumes Docker containers are started externally (e.g., via `make docker-up`).
27pub struct GlobalTestFixture {
28 pub catalog_config: HashMap<String, String>,
29}
30
31static GLOBAL_FIXTURE: OnceLock<GlobalTestFixture> = OnceLock::new();
32
33impl GlobalTestFixture {
34 /// Creates a new GlobalTestFixture from environment variables.
35 /// Uses default localhost endpoints if environment variables are not set.
36 pub fn from_env() -> Self {
37 set_up();
38
39 let rest_endpoint = get_rest_catalog_endpoint();
40 let minio_endpoint = get_minio_endpoint();
41
42 let catalog_config = HashMap::from([
43 (REST_CATALOG_PROP_URI.to_string(), rest_endpoint),
44 (S3_ENDPOINT.to_string(), minio_endpoint),
45 (S3_ACCESS_KEY_ID.to_string(), "admin".to_string()),
46 (S3_SECRET_ACCESS_KEY.to_string(), "password".to_string()),
47 (S3_REGION.to_string(), "us-east-1".to_string()),
48 ]);
49
50 GlobalTestFixture { catalog_config }
51 }
52}
53
54/// Returns a reference to the global test fixture.
55/// This fixture assumes Docker containers are started externally.
56pub fn get_test_fixture() -> &'static GlobalTestFixture {
57 GLOBAL_FIXTURE.get_or_init(GlobalTestFixture::from_env)
58}