Generate more customizable toml blocks for testing
jamesray1 opened this issue · 3 comments
For future extensibility with testing it seems like it would be helpful to generate more customizable tomls, by passing fields or using defaults.
In the case of #1775, the scenario here is that options include:
- create a
pub fn instance1_with_file_storage()
, which is like instance1, just with type = 'file' and path = 'TBD'. Not very elegant - create a toml or toml block from scratch. Again, pretty verbose.
- create a
instance_custom
with optional arguments for each field and defaults.
By extension, this could be extended to other more complex toml block creators that have multiple fields in a block.
Originally posted by @jamesray1 in #1775 (comment)
OTOH, maybe this is overcomplicating things and it would be simpler for #1775 to just create a custom toml block.
From #1775 (comment):
More details:
create_test_conductor
is used intest_remove_instance_clean_true
.create_test_conductor
usestest_toml
, which in turn usesinstance1()
. And, as explained above,instance1()
uses the memory variant of storage, without a persistent path. So in order to create a propertest_remove_instance_clean_true
, that will actually be able to check whether the storage directory is removed, I need a different toml. To do that, it seems like it would be best to be able to pass a different instnace block to what are currently created withtest_toml
andinstance1
. For just this PR, the easiest way seems like to just add an option to select whether to use a memory type, with no path, or a file type, with some path relative to the config path, and then adjust whereverinstance1()
is called.pub fn test_toml(test_name: &str, port: u32) -> String { let mut toml = header_block(test_name); toml = add_block(toml, agent1()); toml = add_block(toml, agent2()); toml = add_block(toml, dna()); toml = add_block(toml, instance1()); toml = add_block(toml, instance2()); toml = add_block(toml, interface(port)); toml = add_block(toml, logger()); toml }
pub fn instance1() -> String { r#"[[instances]] agent = 'test-agent-1' dna = 'test-dna' id = 'test-instance-1' [instances.storage] type = 'memory'"# .to_string() }