Skip to content

Commit

Permalink
fix: fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Oct 25, 2021
1 parent d9e07f9 commit c7f3f23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
24 changes: 15 additions & 9 deletions crates/fed-types/src/build_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use serde::{ser::SerializeSeq, Deserialize, Serialize, Serializer};
#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
pub struct BuildError {
message: Option<String>,
code: String,
code: Option<String>,
r#type: BuildErrorType,
}

impl BuildError {
pub fn composition_error(code: Option<String>, message: Option<String>) -> BuildError {
let code = code.unwrap_or_else(|| "UNKNOWN".to_string());
BuildError {
code,
message,
Expand All @@ -26,7 +25,7 @@ impl BuildError {
self.message.clone()
}

pub fn get_code(&self) -> String {
pub fn get_code(&self) -> Option<String> {
self.code.clone()
}
}
Expand All @@ -39,7 +38,11 @@ pub enum BuildErrorType {

impl Display for BuildError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.code)?;
write!(
f,
"{}",
self.code.as_ref().map_or("UNKNOWN", String::as_str)
)?;
if let Some(message) = &self.message {
write!(f, ": {}", message)?;
}
Expand Down Expand Up @@ -100,7 +103,10 @@ impl BuildErrors {
impl Display for BuildErrors {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let num_failures = self.build_errors.len();
if num_failures == 0 || (num_failures == 1 && self.build_errors[0].to_string() == "UNKNOWN")
if num_failures == 0
|| (num_failures == 1
&& self.build_errors[0].code.is_none()
&& self.build_errors[0].message.is_none())
{
writeln!(f, "Something went wrong! No build errors were recorded, but we also build a valid supergraph SDL.")?;
} else {
Expand Down Expand Up @@ -161,8 +167,8 @@ mod tests {
#[test]
fn it_can_serialize_some_build_errors() {
let build_errors: BuildErrors = vec![
BuildError::composition_error(Some("wow".to_string()), None),
BuildError::composition_error(Some("boo".to_string()), Some("BOO".to_string())),
BuildError::composition_error(None, Some("wow".to_string())),
BuildError::composition_error(Some("BOO".to_string()), Some("boo".to_string())),
]
.into();

Expand All @@ -174,13 +180,13 @@ mod tests {

let expected_value = json!([
{
"code": null,
"message": "wow",
"code": null,
"type": "composition"
},
{
"code": "BOO",
"message": "boo",
"code": "BOO",
"type": "composition"
}
]);
Expand Down
2 changes: 1 addition & 1 deletion installers/binstall/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Installer {

fn extract_plugin_tarball(
&self,
plugin_tarball_url: &str,
_plugin_tarball_url: &str,
) -> Result<Utf8PathBuf, InstallerError> {
std::process::Command::new("cargo")
.args(&["build", "--bin", "rover-fed"])
Expand Down

0 comments on commit c7f3f23

Please sign in to comment.