Skip to content

Commit

Permalink
status: Add a helper to extract the stream
Browse files Browse the repository at this point in the history
Prep for handling the container case in
coreos#878
  • Loading branch information
cgwalters committed Nov 2, 2022
1 parent 749ec87 commit f1c123a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/rpm_ostree/cli_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ pub fn parse_booted(status: &StatusJson) -> Result<Release> {
Ok(json.into_release())
}

fn fedora_coreos_stream_from_deployment(deploy: &DeploymentJson) -> Result<String> {
let stream = deploy.base_metadata.stream.as_str();
ensure!(!stream.is_empty(), "empty stream value");
Ok(stream.to_string())
}

/// Parse updates stream for booted deployment from status object.
pub fn parse_booted_updates_stream(status: &StatusJson) -> Result<String> {
let json = booted_json(status)?;
ensure!(!json.base_metadata.stream.is_empty(), "empty stream value");
Ok(json.base_metadata.stream)
fedora_coreos_stream_from_deployment(&json)
}

/// Parse pending deployment from status object.
Expand All @@ -105,8 +110,7 @@ pub fn parse_pending_deployment(status: &StatusJson) -> Result<Option<(Release,
match staged {
None => Ok(None),
Some(json) => {
let stream = json.base_metadata.stream.clone();
ensure!(!stream.is_empty(), "empty stream value");
let stream = fedora_coreos_stream_from_deployment(&json)?;
let release = json.into_release();
Ok(Some((release, stream)))
}
Expand Down Expand Up @@ -239,6 +243,7 @@ mod tests {
fn mock_booted_updates_stream() {
let status = mock_status("tests/fixtures/rpm-ostree-status.json").unwrap();
let booted = booted_json(&status).unwrap();
assert_eq!(booted.base_metadata.stream, "testing-devel");
let stream = fedora_coreos_stream_from_deployment(&booted).unwrap();
assert_eq!(stream, "testing-devel");
}
}

0 comments on commit f1c123a

Please sign in to comment.