• 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

77.45
/src/app/jobs.rs
1
use k8s_openapi::{api::batch::v1::Job, chrono::Utc};
2

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

5
#[derive(Clone, Debug, PartialEq)]
6✔
6
pub struct KubeJob {
7
  pub name: String,
3✔
8
  pub namespace: String,
3!
9
  pub completions: String,
3!
10
  pub duration: String,
3!
11
  pub age: String,
3!
12
  k8s_obj: Job,
3!
13
}
14

15
impl From<Job> for KubeJob {
16
  fn from(job: Job) -> Self {
3✔
17
    let completions = match (job.spec.as_ref(), job.status.as_ref()) {
3!
18
      (Some(spc), Some(stat)) => match spc.completions {
2✔
19
        Some(c) => format!("{:?}/{:?}", stat.succeeded.unwrap_or_default(), c),
1✔
20
        None => match spc.parallelism {
1!
21
          Some(p) => format!("{:?}/1 of {}", stat.succeeded.unwrap_or_default(), p),
1✔
22
          None => format!("{:?}/1", stat.succeeded),
×
23
        },
24
      },
25
      (None, Some(stat)) => format!("{:?}/1", stat.succeeded.unwrap_or_default()),
1✔
26
      _ => "".into(),
×
27
    };
28

29
    let duration = match job.status.as_ref() {
3!
30
      Some(stat) => match stat.start_time.as_ref() {
3!
31
        Some(st) => match stat.completion_time.as_ref() {
3!
32
          Some(ct) => {
3✔
33
            let duration = ct.0.signed_duration_since(st.0);
3✔
34
            utils::duration_to_age(duration, true)
3✔
35
          }
3✔
36
          None => utils::to_age(stat.start_time.as_ref(), Utc::now()),
×
37
        },
38
        None => "<none>".to_string(),
×
39
      },
40
      None => "<none>".to_string(),
×
41
    };
42

43
    Self {
3✔
44
      name: job.metadata.name.clone().unwrap_or_default(),
3✔
45
      namespace: job.metadata.namespace.clone().unwrap_or_default(),
3✔
46
      completions,
3✔
47
      duration,
3✔
48
      age: utils::to_age(job.metadata.creation_timestamp.as_ref(), Utc::now()),
3✔
49
      k8s_obj: utils::sanitize_obj(job),
3✔
50
    }
51
  }
3✔
52
}
53

54
impl KubeResource<Job> for KubeJob {
55
  fn get_k8s_obj(&self) -> &Job {
×
56
    &self.k8s_obj
×
57
  }
×
58
}
59

60
#[cfg(test)]
61
mod tests {
62
  use super::*;
63
  use crate::app::test_utils::{convert_resource_from_file, get_time};
64

65
  #[test]
66
  fn test_jobs_from_api() {
2✔
67
    let (jobs, jobs_list): (Vec<KubeJob>, Vec<_>) = convert_resource_from_file("jobs");
1✔
68

69
    assert_eq!(jobs.len(), 3);
1!
70
    assert_eq!(
1✔
71
      jobs[0],
1✔
72
      KubeJob {
1✔
73
        name: "helm-install-traefik".into(),
1✔
74
        namespace: "kube-system".into(),
1✔
75
        age: utils::to_age(Some(&get_time("2021-06-11T13:49:45Z")), Utc::now()),
1✔
76
        k8s_obj: jobs_list[0].clone(),
1✔
77
        completions: "1/1".into(),
1✔
78
        duration: "39m44s".into()
1!
79
      }
80
    );
81
    assert_eq!(
1✔
82
      jobs[1],
1✔
83
      KubeJob {
1✔
84
        name: "helm-install-traefik-2".into(),
1✔
85
        namespace: "kube-system".into(),
1✔
86
        age: utils::to_age(Some(&get_time("2021-06-11T13:49:45Z")), Utc::now()),
1✔
87
        k8s_obj: jobs_list[1].clone(),
1✔
88
        completions: "1/1 of 1".into(),
1✔
89
        duration: "39m44s".into()
1!
90
      }
91
    );
92
    assert_eq!(
1✔
93
      jobs[2],
1✔
94
      KubeJob {
1✔
95
        name: "helm-install-traefik-3".into(),
1✔
96
        namespace: "kube-system".into(),
1✔
97
        age: utils::to_age(Some(&get_time("2021-06-11T13:49:45Z")), Utc::now()),
1✔
98
        k8s_obj: jobs_list[2].clone(),
1✔
99
        completions: "1/1".into(),
1✔
100
        duration: "39m44s".into()
1!
101
      }
102
    );
103
  }
2✔
104
}
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