Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:26:59

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <memory>
0021 #include <string>
0022 #include <utility>
0023 
0024 #include <gtest/gtest.h>
0025 
0026 #include "arrow/filesystem/s3fs.h"
0027 #include "arrow/status.h"
0028 #include "arrow/testing/gtest_util.h"
0029 #include "arrow/testing/util.h"
0030 #include "arrow/util/checked_cast.h"
0031 #include "arrow/util/macros.h"
0032 
0033 namespace arrow {
0034 namespace fs {
0035 
0036 // A minio test server, managed as a child process
0037 
0038 class MinioTestServer {
0039  public:
0040   MinioTestServer();
0041   ~MinioTestServer();
0042 
0043   Status Start(bool enable_tls = false);
0044 
0045   Status Stop();
0046 
0047   std::string connect_string() const;
0048 
0049   std::string access_key() const;
0050 
0051   std::string secret_key() const;
0052 
0053   std::string ca_dir_path() const;
0054 
0055   std::string ca_file_path() const;
0056 
0057   std::string scheme() const;
0058 
0059  private:
0060   Status GenerateCertificateFile();
0061   struct Impl;
0062   std::unique_ptr<Impl> impl_;
0063 };
0064 
0065 // A Minio "environment" that spawns Minio processes in advances, such as
0066 // to hide process launch latencies during testing.
0067 
0068 class MinioTestEnvironment : public ::testing::Environment {
0069  public:
0070   explicit MinioTestEnvironment(bool enable_tls = false);
0071   ~MinioTestEnvironment();
0072 
0073   void SetUp() override;
0074 
0075   Result<std::shared_ptr<MinioTestServer>> GetOneServer();
0076 
0077  protected:
0078   struct Impl;
0079   std::unique_ptr<Impl> impl_;
0080 };
0081 
0082 // A global test "environment", to ensure that the S3 API is initialized before
0083 // running unit tests.
0084 
0085 class S3Environment : public ::testing::Environment {
0086  public:
0087   // We set this environment variable to speed up tests by ensuring
0088   // DefaultAWSCredentialsProviderChain does not query (inaccessible)
0089   // EC2 metadata endpoint.
0090   // This must be done before spawning any Minio child process to avoid any race
0091   // condition accessing environment variables.
0092   S3Environment() : ec2_metadata_disabled_guard_("AWS_EC2_METADATA_DISABLED", "true") {}
0093 
0094   void SetUp() override {
0095     // Change this to increase logging during tests
0096     S3GlobalOptions options;
0097     options.log_level = S3LogLevel::Fatal;
0098     ASSERT_OK(InitializeS3(options));
0099   }
0100 
0101   void TearDown() override { ASSERT_OK(FinalizeS3()); }
0102 
0103  private:
0104   EnvVarGuard ec2_metadata_disabled_guard_;
0105 };
0106 
0107 }  // namespace fs
0108 }  // namespace arrow