Skip to content

Commit

Permalink
fix(test): Skip editor files and other hidden files in test configs d…
Browse files Browse the repository at this point in the history
…irectory (#6796)

* Skip editor files and other hidden files in test configs directory

* Also ignore files starting with `#`
  • Loading branch information
teor2345 authored Jun 5, 2023
1 parent a7b0322 commit 628ddd6
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ fn config_tests() -> Result<()> {
// Check that we have a current version of the config stored
last_config_is_stored()?;

// Check that Zebra stored configuration works
stored_configs_works()?;
// Check that Zebra's previous configurations still work
stored_configs_work()?;

// Runs `zebrad` serially to avoid potential port conflicts
app_no_args()?;
Expand Down Expand Up @@ -702,13 +702,31 @@ fn last_config_is_stored() -> Result<()> {
.to_string();

// Loop all the stored configs
//
// TODO: use the same filename list code in last_config_is_stored() and stored_configs_work()
for config_file in configs_dir()
.read_dir()
.expect("read_dir call failed")
.flatten()
{
let config_file_path = config_file.path();
let config_file_name = config_file_path
.file_name()
.expect("config files must have a file name")
.to_string_lossy();

if config_file_name.as_ref().starts_with('.') || config_file_name.as_ref().starts_with('#')
{
// Skip editor files and other invalid config paths
tracing::info!(
?config_file_path,
"skipping hidden/temporary config file path"
);
continue;
}

// Read stored config
let stored_content = fs::read_to_string(config_file_full_path(config_file.path()))
let stored_content = fs::read_to_string(config_file_full_path(config_file_path))
.expect("Should have been able to read the file")
.trim()
.to_string();
Expand Down Expand Up @@ -832,23 +850,41 @@ fn invalid_generated_config() -> Result<()> {

/// Test all versions of `zebrad.toml` we have stored can be parsed by the latest `zebrad`.
#[tracing::instrument]
fn stored_configs_works() -> Result<()> {
fn stored_configs_work() -> Result<()> {
let old_configs_dir = configs_dir();

for config_file in old_configs_dir
.read_dir()
.expect("read_dir call failed")
.flatten()
{
let config_file_path = config_file.path();
let config_file_name = config_file_path
.file_name()
.expect("config files must have a file name")
.to_string_lossy();

if config_file_name.as_ref().starts_with('.') || config_file_name.as_ref().starts_with('#')
{
// Skip editor files and other invalid config paths
tracing::info!(
?config_file_path,
"skipping hidden/temporary config file path"
);
continue;
}

// ignore files starting with getblocktemplate prefix
// if we were not built with the getblocktemplate-rpcs feature.
#[cfg(not(feature = "getblocktemplate-rpcs"))]
if config_file
.file_name()
.into_string()
.expect("all files names should be string convertible")
if config_file_name
.as_ref()
.starts_with(GET_BLOCK_TEMPLATE_CONFIG_PREFIX)
{
tracing::info!(
?config_file_path,
"skipping getblocktemplate-rpcs config file path"
);
continue;
}

Expand Down

0 comments on commit 628ddd6

Please sign in to comment.