Skip to content

Commit

Permalink
Additional URI related cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rdettai committed Jun 26, 2024
1 parent 459346f commit c098bac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 25 deletions.
11 changes: 6 additions & 5 deletions quickwit/quickwit-cli/tests/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
mod helpers;

use std::path::Path;
use std::str::FromStr;

use anyhow::Result;
use clap::error::ErrorKind;
use helpers::{TestEnv, TestStorageType};
use helpers::{uri_from_path, TestEnv, TestStorageType};
use quickwit_cli::checklist::ChecklistError;
use quickwit_cli::cli::build_cli;
use quickwit_cli::index::{
Expand Down Expand Up @@ -258,15 +257,17 @@ async fn test_ingest_docs_cli() {

// Ensure cache directory is empty.
let cache_directory_path = get_cache_directory_path(&test_env.data_dir_path);
let data_dir_uri = Uri::from_str(test_env.data_dir_path.to_str().unwrap()).unwrap();

assert!(cache_directory_path.read_dir().unwrap().next().is_none());

let does_not_exit_uri = uri_from_path(&test_env.data_dir_path)
.join("file-does-not-exist.json")
.unwrap();

// Ingest a non-existing file should fail.
let args = LocalIngestDocsArgs {
config_uri: test_env.resource_files.config,
index_id: test_env.index_id,
input_path_opt: Some(data_dir_uri.join("file-does-not-exist.json").unwrap()),
input_path_opt: Some(does_not_exit_uri),
input_format: SourceInputFormat::Json,
overwrite: false,
clear_cache: true,
Expand Down
18 changes: 9 additions & 9 deletions quickwit/quickwit-cli/tests/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use std::fs;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;

Expand Down Expand Up @@ -191,8 +191,8 @@ pub enum TestStorageType {
LocalFileSystem,
}

fn uri_from_path(path: PathBuf) -> Uri {
Uri::from_str(&format!("file://{}", path.display())).unwrap()
pub fn uri_from_path(path: &Path) -> Uri {
Uri::from_str(path.to_str().unwrap()).unwrap()
}

/// Creates all necessary artifacts in a test environment.
Expand Down Expand Up @@ -264,12 +264,12 @@ pub async fn create_test_env(
.context("failed to parse cluster endpoint")?;

let resource_files = TestResourceFiles {
config: uri_from_path(node_config_path),
index_config: uri_from_path(index_config_path),
index_config_without_uri: uri_from_path(index_config_without_uri_path),
index_config_with_retention: uri_from_path(index_config_with_retention_path),
log_docs: uri_from_path(log_docs_path),
wikipedia_docs: uri_from_path(wikipedia_docs_path),
config: uri_from_path(&node_config_path),
index_config: uri_from_path(&index_config_path),
index_config_without_uri: uri_from_path(&index_config_without_uri_path),
index_config_with_retention: uri_from_path(&index_config_with_retention_path),
log_docs: uri_from_path(&log_docs_path),
wikipedia_docs: uri_from_path(&wikipedia_docs_path),
};

Ok(TestEnv {
Expand Down
2 changes: 1 addition & 1 deletion quickwit/quickwit-common/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub async fn empty_dir<P: AsRef<Path>>(path: P) -> anyhow::Result<()> {
Ok(())
}

/// Helper function to get the cache path.
/// Helper function to get the indexer split cache path.
pub fn get_cache_directory_path(data_dir_path: &Path) -> PathBuf {
data_dir_path.join("indexer-split-cache").join("splits")
}
Expand Down
10 changes: 0 additions & 10 deletions quickwit/quickwit-config/src/source_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
pub(crate) mod serialize;

use std::num::NonZeroUsize;
use std::path::Path;
use std::str::FromStr;

use anyhow::Context;
use bytes::Bytes;
use quickwit_common::is_false;
use quickwit_common::uri::Uri;
Expand Down Expand Up @@ -241,14 +239,6 @@ impl SourceParams {
FileSourceParams::from_str(filepath.as_ref()).map(Self::File)
}

pub fn file_from_path<P: AsRef<Path>>(filepath: P) -> anyhow::Result<Self> {
let path_str = filepath
.as_ref()
.to_str()
.context("failed to convert path to string")?;
Self::file_from_str(path_str)
}

pub fn stdin() -> Self {
Self::File(FileSourceParams { filepath: None })
}
Expand Down

0 comments on commit c098bac

Please sign in to comment.