• 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

79.87
/src/app/roles.rs
1
use k8s_openapi::{
2
  api::rbac::v1::{ClusterRole, ClusterRoleBinding, Role, RoleBinding},
3
  chrono::Utc,
4
};
5

6
use super::{models::KubeResource, utils};
7

8
#[derive(Clone, Debug, PartialEq)]
2✔
9
pub struct KubeRole {
10
  pub namespace: String,
1✔
11
  pub name: String,
1!
12
  pub age: String,
1!
13
  k8s_obj: Role,
1!
14
}
15

16
#[derive(Clone, Debug, PartialEq)]
2✔
17
pub struct KubeRoleBinding {
18
  pub namespace: String,
1✔
19
  pub name: String,
1!
20
  pub role: String,
1!
21
  pub age: String,
1!
22
  k8s_obj: RoleBinding,
1!
23
}
24

25
#[derive(Clone, Debug, PartialEq)]
2✔
26
pub struct KubeClusterRole {
27
  pub name: String,
1✔
28
  pub age: String,
1!
29
  k8s_obj: ClusterRole,
1!
30
}
31

32
#[derive(Clone, Debug, PartialEq)]
2✔
33
pub struct KubeClusterRoleBinding {
34
  pub name: String,
1✔
35
  pub role: String,
1!
36
  pub age: String,
1!
37
  k8s_obj: ClusterRoleBinding,
1!
38
}
39

40
impl From<Role> for KubeRole {
41
  fn from(role: Role) -> Self {
1✔
42
    KubeRole {
1✔
43
      namespace: role.metadata.namespace.clone().unwrap_or_default(),
1✔
44
      name: role.metadata.name.clone().unwrap_or_default(),
1✔
45
      age: utils::to_age(role.metadata.creation_timestamp.as_ref(), Utc::now()),
1✔
46
      k8s_obj: utils::sanitize_obj(role),
1✔
47
    }
48
  }
1✔
49
}
50

51
impl KubeResource<Role> for KubeRole {
52
  fn get_k8s_obj(&self) -> &Role {
×
53
    &self.k8s_obj
×
54
  }
×
55
}
56

57
impl From<ClusterRole> for KubeClusterRole {
58
  fn from(cluster_role: ClusterRole) -> Self {
1✔
59
    KubeClusterRole {
1✔
60
      name: cluster_role.metadata.name.clone().unwrap_or_default(),
1✔
61
      age: utils::to_age(
1✔
62
        cluster_role.metadata.creation_timestamp.as_ref(),
1✔
63
        Utc::now(),
1✔
64
      ),
65
      k8s_obj: utils::sanitize_obj(cluster_role),
1✔
66
    }
67
  }
1✔
68
}
69

70
impl KubeResource<ClusterRole> for KubeClusterRole {
71
  fn get_k8s_obj(&self) -> &ClusterRole {
×
72
    &self.k8s_obj
×
73
  }
×
74
}
75

76
impl From<RoleBinding> for KubeRoleBinding {
77
  fn from(role_binding: RoleBinding) -> Self {
1✔
78
    KubeRoleBinding {
1✔
79
      namespace: role_binding.metadata.namespace.clone().unwrap_or_default(),
1✔
80
      name: role_binding.metadata.name.clone().unwrap_or_default(),
1✔
81
      role: role_binding.role_ref.name.clone(),
1✔
82
      age: utils::to_age(
1✔
83
        role_binding.metadata.creation_timestamp.as_ref(),
1✔
84
        Utc::now(),
1✔
85
      ),
86
      k8s_obj: utils::sanitize_obj(role_binding),
1✔
87
    }
88
  }
1✔
89
}
90
impl KubeResource<RoleBinding> for KubeRoleBinding {
91
  fn get_k8s_obj(&self) -> &RoleBinding {
×
92
    &self.k8s_obj
93
  }
×
94
}
95

96
impl From<ClusterRoleBinding> for KubeClusterRoleBinding {
97
  fn from(crb: ClusterRoleBinding) -> Self {
2✔
98
    KubeClusterRoleBinding {
2✔
99
      name: crb.metadata.name.clone().unwrap_or_default(),
2✔
100
      role: format!("{}/{}", crb.role_ref.kind, crb.role_ref.name),
2✔
101
      age: utils::to_age(crb.metadata.creation_timestamp.as_ref(), Utc::now()),
2✔
102
      k8s_obj: utils::sanitize_obj(crb),
2✔
103
    }
104
  }
2✔
105
}
106

107
impl KubeResource<ClusterRoleBinding> for KubeClusterRoleBinding {
108
  fn get_k8s_obj(&self) -> &ClusterRoleBinding {
×
109
    &self.k8s_obj
110
  }
×
111
}
112

113
#[cfg(test)]
114
mod tests {
115
  use k8s_openapi::chrono::Utc;
116

117
  use crate::app::{
118
    roles::{KubeClusterRole, KubeClusterRoleBinding, KubeRole, KubeRoleBinding},
119
    test_utils::{convert_resource_from_file, get_time},
120
    utils,
121
  };
122

123
  #[test]
124
  fn test_roles_binding_from_rbac_api() {
2✔
125
    let (roles, roles_list): (Vec<KubeRole>, Vec<_>) = convert_resource_from_file("roles");
1✔
126

127
    assert_eq!(roles.len(), 1);
1!
128
    assert_eq!(
1✔
129
      roles[0],
1✔
130
      KubeRole {
1✔
131
        namespace: "default".to_string(),
1✔
132
        name: "kiali-viewer".into(),
1✔
133
        age: utils::to_age(Some(&get_time("2022-06-27T16:33:06Z")), Utc::now()),
1✔
134
        k8s_obj: roles_list[0].clone(),
1!
135
      }
136
    )
137
  }
2✔
138

139
  #[test]
140
  fn test_cluster_roles_from_rbac_api() {
2✔
141
    let (cluster_roles, cluster_roles_list): (Vec<KubeClusterRole>, Vec<_>) =
1✔
142
      convert_resource_from_file("clusterroles");
1✔
143

144
    assert_eq!(cluster_roles.len(), 1);
1!
145
    assert_eq!(
1✔
146
      cluster_roles[0],
1✔
147
      KubeClusterRole {
1✔
148
        name: "admin".into(),
1✔
149
        age: utils::to_age(Some(&get_time("2021-12-14T11:04:22Z")), Utc::now()),
1✔
150
        k8s_obj: cluster_roles_list[0].clone(),
1!
151
      }
152
    )
153
  }
2✔
154

155
  #[test]
156
  fn test_role_binding_from_rbac_api() {
2✔
157
    let (role_bindings, rolebindings_list): (Vec<KubeRoleBinding>, Vec<_>) =
1✔
158
      convert_resource_from_file("role_bindings");
1✔
159

160
    assert_eq!(role_bindings.len(), 1);
1!
161
    assert_eq!(
1✔
162
      role_bindings[0],
1✔
163
      KubeRoleBinding {
1✔
164
        namespace: "default".to_string(),
1✔
165
        name: "kiali".into(),
1✔
166
        role: "kiali-viewer".into(),
1✔
167
        age: utils::to_age(Some(&get_time("2022-06-27T16:33:07Z")), Utc::now()),
1✔
168
        k8s_obj: rolebindings_list[0].clone(),
1!
169
      }
170
    )
171
  }
2✔
172

173
  #[test]
174
  fn test_cluster_role_bindings_from_rbac_api() {
2✔
175
    let (cluster_role_binding, cluster_role_bindings_list): (Vec<KubeClusterRoleBinding>, Vec<_>) =
1✔
176
      convert_resource_from_file("clusterrole_binding");
1✔
177

178
    assert_eq!(cluster_role_binding.len(), 2);
1!
179
    assert_eq!(
1✔
180
      cluster_role_binding[0],
1✔
181
      KubeClusterRoleBinding {
1✔
182
        name: "admin-user".into(),
1✔
183
        role: "ClusterRole/cluster-admin".into(),
1✔
184
        age: utils::to_age(Some(&get_time("2022-03-02T16:50:53Z")), Utc::now()),
1✔
185
        k8s_obj: cluster_role_bindings_list[0].clone(),
1!
186
      }
187
    )
188
  }
2✔
189
}
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