Skip to content

Commit

Permalink
fixed issue with tests faililng due to not finding config
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbuffalo committed Aug 20, 2023
1 parent 7a634fd commit e2d9593
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 24 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "sciflow"
name = "scidataflow"
version = "0.1.0"
edition = "2021"
include = ["src/**/*", "tests/test_data/**/*"]

[lib]
name = "sciflow"
name = "scidataflow"
path = "src/lib.rs"

[[bin]]
Expand Down
4 changes: 2 additions & 2 deletions src/lib/api/zenodo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl TryInto<ZenodoDepositionData> for LocalMetadata {
fn try_into(self) -> Result<ZenodoDepositionData> {
let name = self.author_name.ok_or_else(|| anyhow!("Author name is required"))?;
// TODO? Warn user of default description?
let description = self.description.unwrap_or("Upload by SciFlow.".to_string());
let description = self.description.unwrap_or("Upload by SciDataFlow.".to_string());

Ok(ZenodoDepositionData {
metadata: ZenodoMetadata {
Expand Down Expand Up @@ -260,7 +260,7 @@ mod tests {
use serde_json::json;
use crate::logging_setup::setup;

//#[tokio::test]
#[tokio::test]
async fn test_remote_init_success() {
setup();
// Start a mock server
Expand Down
26 changes: 13 additions & 13 deletions src/lib/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn find_manifest(start_dir: Option<&PathBuf>, filename: &str) -> Option<Path
pub fn config_path() -> Result<PathBuf> {
let mut config_path: PathBuf = dirs::home_dir()
.ok_or_else(|| anyhow!("Cannot load home directory!"))?;
config_path.push(".sciflow_config");
config_path.push(".scidataflow_config");
Ok(config_path)
}

Expand Down Expand Up @@ -97,20 +97,20 @@ pub struct Project {

impl Project {
fn get_manifest() -> Result<PathBuf> {
find_manifest(None, MANIFEST).ok_or(anyhow!("SciFlow not initialized."))
find_manifest(None, MANIFEST).ok_or(anyhow!("SciDataFlow not initialized."))
}

pub fn load_config() -> Result<Config> {
let config_path = config_path()?;
let mut file = File::open(&config_path)
.with_context(|| format!("No sciflow config found at \
{:?}. Please set with scf config --user <NAME> \
[--email <EMAIL> --affil <AFFILIATION>]", &config_path))?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

let config: Config = serde_yaml::from_str(&contents)?;
Ok(config)
.map_err(|_| anyhow!("No SciDataFlow config found at \
{:?}. Please set with scf config --user <NAME> \
[--email <EMAIL> --affil <AFFILIATION>]", &config_path))?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;

let config: Config = serde_yaml::from_str(&contents)?;
Ok(config)
}

pub fn save_config(config: Config) -> Result<()> {
Expand All @@ -122,10 +122,10 @@ impl Project {
}

pub fn new() -> Result<Self> {
let manifest = Project::get_manifest()?;
let manifest = Project::get_manifest().context("Failed to get the manifest")?;
info!("manifest: {:?}", manifest);
let data = Project::load(&manifest)?;
let config = Project::load_config()?;
let data = Project::load(&manifest).context("Failed to load data from the manifest")?;
let config = Project::load_config().context("Failed to load the project configuration")?;
let proj = Project { manifest, data, config };
Ok(proj)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::lib::api::zenodo::ZenodoAPI;
use crate::lib::project::LocalMetadata;


const AUTHKEYS: &str = ".sciflow_authkeys.yml";
const AUTHKEYS: &str = ".scidataflow_authkeys.yml";

#[derive(Debug, Clone, PartialEq)]
pub struct DownloadInfo {
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use structopt::StructOpt;
#[allow(unused_imports)]
use log::{info, trace, debug};

use sciflow::lib::project::Project;
use sciflow::logging_setup::setup;
use scidataflow::lib::project::Project;
use scidataflow::logging_setup::setup;

pub mod logging_setup;

const INFO: &str = "\
SciFlow: Manage and Share Scientific Data
SciDataFlow: Manage and Share Scientific Data
usage: scf [--help] <subcommand>
Some examples:
Expand Down
9 changes: 7 additions & 2 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use rand::rngs::StdRng;
use rand::SeedableRng;
use lazy_static::lazy_static;

use sciflow::lib::project::Project;
use sciflow::lib::data::StatusEntry;
use scidataflow::lib::project::Project;
use scidataflow::lib::data::StatusEntry;

pub fn make_mock_fixtures() -> Vec<DataFileFixture> {
let files = vec![
Expand Down Expand Up @@ -190,6 +190,11 @@ pub fn setup(do_add: bool) -> TestFixture {
let _ = test_env.build_project_directories(data_fixtures);

// initializes sciflow in the test environment
let current_dir = env::current_dir().unwrap();
info!("temp_dir: {:?}, current directory: {:?}", test_env.temp_dir, current_dir);
let _ = Project::set_config(&Some("Joan B. Scientist".to_string()),
&Some("[email protected]".to_string()),
&Some("UC Berkeley".to_string()));
let _ = Project::init(Some(project_name));
let mut project = Project::new().expect("setting up TestFixture failed");

Expand Down
2 changes: 1 addition & 1 deletion tests/test_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod tests {
use super::get_statuses;
use super::generate_random_tsv;
use std::path::PathBuf;
use sciflow::lib::data::LocalStatusCode;
use scidataflow::lib::data::LocalStatusCode;

#[test]
fn test_fixture() {
Expand Down

0 comments on commit e2d9593

Please sign in to comment.