Skip to content

Commit

Permalink
TestManager: Add flexibility to displayed columns
Browse files Browse the repository at this point in the history
  • Loading branch information
ecpullen committed Mar 1, 2023
1 parent 609fe27 commit 01c2afe
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 342 deletions.
23 changes: 11 additions & 12 deletions cli/src/status.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use anyhow::{Context, Result};
use clap::Parser;
use terminal_size::{Height, Width};
use testsys_model::test_manager::{
CrdState, CrdType, SelectionParams, StatusProgress, TestManager,
};
use testsys_model::test_manager::{CrdState, CrdType, SelectionParams, StatusColumn, TestManager};

/// Check the status of a TestSys object.
#[derive(Debug, Parser)]
Expand All @@ -20,10 +18,6 @@ pub(crate) struct Status {
#[clap(long, short = 'p')]
progress: bool,

/// Include the `Test` status, too. Requires `--progress`
#[clap(long, requires("progress"))]
with_test: bool,

/// Include the time the CRD was last updated
#[clap(long, short = 'u')]
with_time: bool,
Expand Down Expand Up @@ -68,14 +62,19 @@ impl Status {
.await
.context("Unable to get status")?;

if self.with_test {
status.with_progress(StatusProgress::WithTests);
} else if self.progress {
status.with_progress(StatusProgress::Resources);
status.add_column(StatusColumn::name());
status.add_column(StatusColumn::crd_type());
status.add_column(StatusColumn::state());
status.add_column(StatusColumn::passed());
status.add_column(StatusColumn::failed());
status.add_column(StatusColumn::skipped());

if self.progress {
status.add_column(StatusColumn::progress());
}

if self.with_time {
status.with_time();
status.add_column(StatusColumn::last_update());
}

if self.json {
Expand Down
30 changes: 3 additions & 27 deletions model/src/test_manager/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
SelectionParams, StatusSnapshot,
};
use crate::clients::{AllowNotFound, CrdClient, ResourceClient, TestClient};
use crate::constants::{LABEL_COMPONENT, TESTSYS_RESULTS_FILE};
use crate::constants::TESTSYS_RESULTS_FILE;
use crate::system::AgentType;
use crate::{Crd, CrdName, Resource, SecretName, TaskState, Test, TestUserState};
use bytes::Bytes;
Expand Down Expand Up @@ -296,34 +296,10 @@ impl TestManager {
/// returned can be used to print a table containing each objects status (including rerun tests)
/// or to print a json representation containing all included objects as well as the controller
/// status.
pub async fn status(
&self,
selection_params: &SelectionParams,
include_controller: bool,
) -> Result<StatusSnapshot> {
let controller_status = if include_controller {
let pod_api: Api<Pod> = self.namespaced_api();
let pods = pod_api
.list(&ListParams {
label_selector: Some(format!("{}={}", LABEL_COMPONENT, "controller")),
..Default::default()
})
.await
.context(error::KubeSnafu {
action: "get controller pod",
})?
.items;
if let Some(pod) = pods.first() {
pod.status.clone()
} else {
None
}
} else {
None
};
pub async fn status(&self, selection_params: &SelectionParams) -> Result<StatusSnapshot> {
let crds = self.list(selection_params).await?;

Ok(StatusSnapshot::new(controller_status, crds))
Ok(StatusSnapshot::new(crds))
}

/// Retrieve the logs of a test.
Expand Down
9 changes: 1 addition & 8 deletions model/src/test_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use error::{Error, Result};
pub use manager::{read_manifest, TestManager};
use serde::{Deserialize, Serialize};
use serde_plain::derive_fromstr_from_deserialize;
pub use status::StatusSnapshot;
pub use status::{StatusColumn, StatusSnapshot};
use std::collections::HashMap;

mod delete;
Expand Down Expand Up @@ -85,10 +85,3 @@ pub enum ResourceState {
}

derive_fromstr_from_deserialize!(ResourceState);

/// `StatusProgress` represents whether a `Test`'s `other_info` should be included or not.
#[derive(Debug)]
pub enum StatusProgress {
WithTests,
Resources,
}
Loading

0 comments on commit 01c2afe

Please sign in to comment.