Skip to content

Commit

Permalink
fix bug from updating tabled
Browse files Browse the repository at this point in the history
The name field is now used as the index in our transposition and should
not be removed.
  • Loading branch information
cbgbt committed Aug 1, 2024
1 parent 0de910d commit ac59c47
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions model/src/test_manager/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ impl From<&StatusSnapshot> for Table {

let mut table = Builder::from_iter(status_data)
.index()
// index is needed to use `transpose` however, we don't want the index to show, so
// `hide` is used as well.
.hide()
.transpose()
.to_owned()
.build();
Expand Down Expand Up @@ -381,3 +378,63 @@ fn crd_progress(crd: &Crd) -> Vec<String> {
.collect(),
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::{Test, TestSpec};
use kube::api::ObjectMeta;
use std::collections::BTreeMap;

fn create_test_crd(
name: &str,
namespace: &str,
labels: Option<&BTreeMap<String, String>>,
test_spec: TestSpec,
) -> Test {
Test {
metadata: ObjectMeta {
name: Some(name.to_owned()),
namespace: Some(namespace.to_owned()),
labels: labels.cloned(),
..Default::default()
},
spec: test_spec,
status: None,
}
}

#[test]
fn status_snapshot() {
let crds = vec![
Crd::Test(create_test_crd(
"test1-name",
"test",
None,
TestSpec::default(),
)),
Crd::Test(create_test_crd(
"test2-name",
"test",
None,
TestSpec::default(),
)),
];
let mut snapshot = StatusSnapshot::new(crds);
snapshot.add_column(StatusColumn::name());
snapshot.add_column(StatusColumn::crd_type());
snapshot.add_column(StatusColumn::state());
snapshot.add_column(StatusColumn::passed());
snapshot.add_column(StatusColumn::failed());
snapshot.add_column(StatusColumn::skipped());

let snapshot_str = format!("{:width$}", &snapshot, width = 80);
let expected =
" NAME TYPE STATE PASSED FAILED SKIPPED
test1-name Test unknown
test2-name Test unknown ";

println!("{}", snapshot_str);
assert_eq!(snapshot_str, expected);
}
}

0 comments on commit ac59c47

Please sign in to comment.