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

fix: consumerVersionTags got overwritten with empty array #714

Merged
merged 1 commit into from
Jul 22, 2021
Merged
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
92 changes: 55 additions & 37 deletions native/src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,35 +39,42 @@ fn get_bool_value(cx: &mut FunctionContext, obj: &JsObject, name: &str) -> bool
}
}

fn get_string_array(cx: &mut FunctionContext, obj: &JsObject, name: &str) -> Result<Vec<String>, String> {
match obj.get(cx, name) {
Ok(items) => match items.downcast::<JsString>() {
Ok(item) => Ok(vec![ item.value().to_string() ]),
Err(_) => match items.downcast::<JsArray>() {
Ok(items) => {
let mut tags = vec![];
if let Ok(items) = items.to_vec(cx) {
for tag in items {
match tag.downcast::<JsString>() {
Ok(val) => tags.push(val.value().to_string()),
Err(_) => {
println!(" {}", Red.paint(format!("ERROR: {} must be a string or array of strings", name)));
}
fn get_string_array(
cx: &mut FunctionContext,
obj: &JsObject,
name: &str,
) -> Result<Option<Vec<String>>, String> {
if let Ok(items) = obj.get(cx, name) {
match items.downcast::<JsString>() {
Ok(item) => return Ok(Some(vec![item.value().to_string()])),
Err(_) => match items.downcast::<JsArray>() {
Ok(items) => {
let mut tags = vec![];
if let Ok(items) = items.to_vec(cx) {
for tag in items {
match tag.downcast::<JsString>() {
Ok(val) => tags.push(val.value().to_string()),
Err(_) => {
return Err(format!(
"{} must be a string or array of strings",
name
));
}
}
}
};
return Ok(Some(tags));
}
}
};
Ok(tags)
},
Err(_) => if !items.is_a::<JsUndefined>() {
println!(" {}", Red.paint(format!("ERROR: {} must be a string or array of strings", name)));
Err(format!("{} must be a string or array of strings", name))
} else {
Ok(vec![])
}
Err(_) => {
if !items.is_a::<JsUndefined>() {
return Err(format!("{} must be a string or array of strings", name));
}
}
},
}
},
_ => Ok(vec![])
}
};

Ok(None)
}

fn get_integer_value(cx: &mut FunctionContext, obj: &JsObject, name: &str) -> Option<u64> {
Expand Down Expand Up @@ -238,23 +245,34 @@ pub fn verify_provider(mut cx: FunctionContext) -> JsResult<JsUndefined> {
};

let provider_tags = match get_string_array(&mut cx, &config, "providerVersionTags") {
Ok(tags) => tags,
Err(e) => return cx.throw_error(e)
Ok(tags) => tags.unwrap_or(vec![]),
Err(e) => {
eprintln!(" {}", Red.paint(format!("ERROR: {}", e)));
return cx.throw_error(e);
}
};

match config.get(&mut cx, "pactBrokerUrl") {
Ok(url) => match url.downcast::<JsString>() {
Ok(url) => {
let pending = get_bool_value(&mut cx, &config, "enablePending");
let wip = get_string_value(&mut cx, &config, "includeWipPactsSince");
let consumer_version_tags = match get_string_array(&mut cx, &config, "consumerVersionTags") {
Ok(tags) => Some(tags),
Err(e) => return cx.throw_error(e)
};
let consumer_version_selectors = match get_string_array(&mut cx, &config, "consumerVersionSelectorsString") {
Ok(tags) => Some(tags),
Err(e) => return cx.throw_error(e)
};
let consumer_version_tags =
match get_string_array(&mut cx, &config, "consumerVersionTags") {
Ok(vt) => vt,
Err(e) => {
eprintln!(" {}", Red.paint(format!("ERROR: {}", e)));
return cx.throw_error(e);
}
};
let consumer_version_selectors =
match get_string_array(&mut cx, &config, "consumerVersionSelectorsString") {
Ok(vs) => vs,
Err(e) => {
eprintln!(" {}", Red.paint(format!("ERROR: {}", e)));
return cx.throw_error(e);
}
};

let selectors = match (consumer_version_selectors, consumer_version_tags) {
(Some(vs), _) => json_to_selectors(vs),
Expand Down