kou commented on code in PR #12914: URL: https://github.com/apache/arrow/pull/12914#discussion_r931676422
########## cpp/src/arrow/filesystem/azurefs_test.cc: ########## @@ -0,0 +1,531 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "arrow/filesystem/azurefs.h" + +#include <gmock/gmock-matchers.h> +#include <gmock/gmock-more-matchers.h> +#include <gtest/gtest.h> +#include <azure/storage/files/datalake.hpp> +#include <boost/process.hpp> +#include <chrono> +#include <thread> + +#include "arrow/filesystem/test_util.h" +#include "arrow/testing/future_util.h" +#include "arrow/testing/gtest_util.h" +#include "arrow/testing/util.h" +#include "arrow/util/io_util.h" +#include "arrow/util/key_value_metadata.h" +#include "arrow/util/logging.h" +#include "arrow/util/uri.h" + +namespace arrow { + +using internal::Uri; + +namespace fs { +namespace internal { + +namespace bp = boost::process; + +using ::arrow::internal::TemporaryDir; +using ::testing::IsEmpty; +using ::testing::NotNull; + +class AzuriteEnv : public ::testing::Environment { + public: + AzuriteEnv() { + account_name_ = "devstoreaccount1"; + account_key_ = + "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/" + "KBHBeksoGMGw=="; + auto exe_path = bp::search_path("azurite"); + if (exe_path.empty()) { + auto error = std::string("Could not find Azurite emulator."); + status_ = Status::Invalid(error); + return; + } + auto temp_dir_ = TemporaryDir::Make("azurefs-test-").ValueOrDie(); + server_process_ = bp::child(boost::this_process::environment(), exe_path, "--silent", + "--location", temp_dir_->path().ToString(), "--debug", + temp_dir_->path().ToString() + "/debug.log"); + if (!(server_process_.valid() && server_process_.running())) { + auto error = "Could not start Azurite emulator."; + server_process_.terminate(); + server_process_.wait(); + status_ = Status::Invalid(error); + return; + } + status_ = Status::OK(); + } + + ~AzuriteEnv() override { + server_process_.terminate(); + server_process_.wait(); + } + + const std::string& account_name() const { return account_name_; } + const std::string& account_key() const { return account_key_; } + const Status status() const { return status_; } + + private: + std::string account_name_; + std::string account_key_; + bp::child server_process_; + Status status_; + std::unique_ptr<TemporaryDir> temp_dir_; +}; + +auto* azurite_env = ::testing::AddGlobalTestEnvironment(new AzuriteEnv); + +AzuriteEnv* GetAzuriteEnv() { + return ::arrow::internal::checked_cast<AzuriteEnv*>(azurite_env); +} + +class TestAzureFileSystem : public ::testing::Test { + public: + std::shared_ptr<FileSystem> fs_; + std::shared_ptr<Azure::Storage::Files::DataLake::DataLakeServiceClient> gen2_client_; + AzureOptions options_; + + void MakeFileSystem() { + const std::string& account_name = GetAzuriteEnv()->account_name(); + const std::string& account_key = GetAzuriteEnv()->account_key(); + options_.is_azurite = true; + options_.ConfigureAccountKeyCredentials(account_name, account_key); + gen2_client_ = + std::make_shared<Azure::Storage::Files::DataLake::DataLakeServiceClient>( + options_.account_dfs_url, options_.storage_credentials_provider); + ASSERT_OK_AND_ASSIGN(fs_, AzureBlobFileSystem::Make(options_)); + } + + void SetUp() override { + ASSERT_THAT(GetAzuriteEnv(), NotNull()); + ASSERT_THAT(GetAzuriteEnv()->status(), Status::OK()); Review Comment: Can we use `ASSERT_OK()` here? https://github.com/apache/arrow/blob/master/cpp/src/arrow/testing/gtest_util.h#L87 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
