Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factors: Update runtime config and tests #2686

Merged
merged 1 commit into from
Jul 29, 2024
Merged

Conversation

lann
Copy link
Collaborator

@lann lann commented Jul 26, 2024

I swear this started out as a focused commit...

Anyway: this is a random grab-bag of changes to simplify and homogenize factors runtime config and tests:

  • Simplify runtime config handling in RuntimeFactors::configure_app
  • Add #[derive(Default)] to derived RuntimeFactors' runtime configs; replace () as an "empty source" with Default::default()
  • Change TestEnvironment to use a builder-style interface
  • Simplify or inline some test helpers
  • Homogenize factors tests a bit, including:
    • Rename all factor test files to factor_test.rs (commence bikeshedding!)
    • Remove some now-unnecessary WasiFactor deps

Comment on lines +55 to +60
type EnvFetcherFn = Box<dyn Fn(&str) -> Result<String, VarError> + Send + Sync>;

/// A config Provider that uses environment variables.
pub struct EnvVariablesProvider {
prefix: Option<String>,
env_fetcher: Box<dyn Fn(&str) -> Result<String, VarError> + Send + Sync>,
env_fetcher: EnvFetcherFn,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy

@lann lann requested a review from rylev July 26, 2024 20:25
Copy link
Collaborator

@rylev rylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I'm going to merge this just so we don't run into any conflicts down the line.

let mut env = Self::default();
env.manifest.extend(manifest_merge);
env
pub fn extend_manifest(mut self, manifest_merge: toml::Table) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be mimicking a builder pattern. Normally this would be a separate struct with a build method, but I think in this case, just mutating the TestEnvironment is fine. Just wanted to note it here as a place for potential future change.

factors,
TomlRuntimeSource::new(&runtime_config, sqlite_config),
)
let env = TestEnvironment::new(factors)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let env = TestEnvironment::new(factors)
let _ = TestEnvironment::new(factors)

I'm surprised this doesn't lead to a warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env is used at 77

@rylev rylev merged commit de120b6 into fermyon:factors Jul 29, 2024
2 checks passed
@lann lann deleted the update-test-env branch July 29, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants