• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kdash-rs / kdash / 3750513782

pending completion
3750513782

push

github

Deepu
fix tests

982 of 4441 branches covered (22.11%)

Branch coverage included in aggregate %.

2731 of 4724 relevant lines covered (57.81%)

8.14 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.38
/src/app/cronjobs.rs
1
use k8s_openapi::{api::batch::v1::CronJob, chrono::Utc};
2

3
use super::{models::KubeResource, utils};
4

5
#[derive(Clone, Debug, PartialEq)]
2✔
6
pub struct KubeCronJob {
7
  pub name: String,
1✔
8
  pub namespace: String,
1!
9
  pub schedule: String,
1!
10
  pub last_schedule: String,
1!
11
  pub suspend: bool,
1!
12
  pub active: usize,
1!
13
  pub age: String,
1!
14
  k8s_obj: CronJob,
1!
15
}
16

17
impl From<CronJob> for KubeCronJob {
18
  fn from(cronjob: CronJob) -> Self {
1✔
19
    let (last_schedule, active) = match &cronjob.status {
2!
20
      Some(cjs) => (
2✔
21
        utils::to_age_secs(cjs.last_schedule_time.as_ref(), Utc::now()),
1✔
22
        cjs.active.clone().unwrap_or_default().len(),
1✔
23
      ),
1✔
24
      None => ("<none>".to_string(), 0),
×
25
    };
26

27
    let (schedule, suspend) = match &cronjob.spec {
2!
28
      Some(cjs) => (cjs.schedule.clone(), cjs.suspend.unwrap_or_default()),
1✔
29
      None => ("".to_string(), false),
×
30
    };
31

32
    KubeCronJob {
1✔
33
      name: cronjob.metadata.name.clone().unwrap_or_default(),
1✔
34
      namespace: cronjob.metadata.namespace.clone().unwrap_or_default(),
1✔
35
      schedule,
1✔
36
      suspend,
37
      last_schedule,
1✔
38
      active,
39
      age: utils::to_age(cronjob.metadata.creation_timestamp.as_ref(), Utc::now()),
1✔
40
      k8s_obj: utils::sanitize_obj(cronjob),
1✔
41
    }
42
  }
1✔
43
}
44
impl KubeResource<CronJob> for KubeCronJob {
45
  fn get_k8s_obj(&self) -> &CronJob {
×
46
    &self.k8s_obj
×
47
  }
×
48
}
49

50
#[cfg(test)]
51
mod tests {
52
  use super::*;
53
  use crate::app::test_utils::{convert_resource_from_file, get_time};
54

55
  #[test]
56
  fn test_cronjobs_from_api() {
2✔
57
    let (jobs, jobs_list): (Vec<KubeCronJob>, Vec<_>) = convert_resource_from_file("cronjobs");
1✔
58

59
    assert_eq!(jobs.len(), 1);
1!
60
    assert_eq!(
1✔
61
      jobs[0],
1✔
62
      KubeCronJob {
1✔
63
        name: "hello".into(),
1✔
64
        namespace: "default".into(),
1✔
65
        schedule: "*/1 * * * *".into(),
1✔
66
        suspend: false,
67
        active: 0,
68
        last_schedule: utils::to_age_secs(Some(&get_time("2021-07-05T09:39:00Z")), Utc::now()),
1✔
69
        age: utils::to_age(Some(&get_time("2021-07-05T09:37:21Z")), Utc::now()),
1✔
70
        k8s_obj: jobs_list[0].clone(),
1!
71
      }
72
    );
73
  }
2✔
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc