Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,6 @@ impl Default for InjectedFieldConfig {
impl Validate for InjectedFieldConfig {
fn validate(&self) -> Result<()> {
validate_field_name(&self.name)?;
if self.value.is_empty() {
bail!("'{}': value must not be empty", self.name);
}
parse_typed_cell(&self.value, self.kind).with_context(|| format!("'{}'", self.name))?;
Ok(())
}
Expand Down Expand Up @@ -1212,6 +1209,24 @@ fields = [
);
}

#[test]
fn test_injected_field_accepts_empty_text_value() {
let dir = tempfile::tempdir().unwrap();
let extra = "[[injected-fields]]\nname = \"note\"\ntype = \"TEXT\"\nvalue = \"\"\n";
fs::write(dir.path().join("config.toml"), minimal_config_with(extra)).unwrap();
let config = Config::load(dir.path()).unwrap();
assert_eq!(config.injected_fields[0].value, "");
}

#[test]
fn test_injected_field_rejects_empty_number_value() {
let dir = tempfile::tempdir().unwrap();
let extra = "[[injected-fields]]\nname = \"seq\"\ntype = \"NUMBER\"\nvalue = \"\"\n";
fs::write(dir.path().join("config.toml"), minimal_config_with(extra)).unwrap();
let err = Config::load(dir.path()).expect_err("expected validation error");
assert!(format!("{:#}", err).contains("invalid number"));
}

fn minimal_config_with(extra: &str) -> String {
format!(
"{}\n[tables.users]\nfields = [\n {{ name = \"id\", type = \"NUMBER\", primary-key = true }},\n]\n",
Expand Down
30 changes: 0 additions & 30 deletions tests/accept_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,36 +358,6 @@ source = "users.csv"
);
}

#[test]
fn test_injected_field_empty_value_rejected() {
common::init_logging();
let tmp = tempfile::tempdir().unwrap();
common::write_config(
tmp.path(),
"config.toml",
r#"
[[injected-fields]]
name = "host"
value = ""

[tables.users]
fields = [
{ name = "id", type = "NUMBER", primary-key = true },
{ name = "name", type = "TEXT" },
]

[tables.users.csv]
source = "users.csv"
"#,
);

let err = format!("{:#}", Config::load(tmp.path()).unwrap_err());
assert!(
err.contains("value must not be empty"),
"should report empty value: {err}"
);
}

#[test]
fn test_injected_field_value_does_not_parse() {
common::init_logging();
Expand Down
Loading