#[cfg(test)]
mod traits_tests {
use k8s_openapi::api::core::v1::{ConfigMap, Namespace, Node, Pod, Secret, ServiceAccount};
use k8s_openapi::api::rbac::v1::{ClusterRole, ClusterRoleBinding};
use crate::traits::{ClusterResource, KubeResource, NamespacedResource};
fn assert_kube_resource<T: KubeResource>() {}
fn assert_namespaced<T: NamespacedResource>() {}
fn assert_cluster<T: ClusterResource>() {}
#[test]
fn pod_satisfies_kube_resource() {
assert_kube_resource::<Pod>();
}
#[test]
fn configmap_satisfies_kube_resource() {
assert_kube_resource::<ConfigMap>();
}
#[test]
fn secret_satisfies_kube_resource() {
assert_kube_resource::<Secret>();
}
#[test]
fn service_account_satisfies_kube_resource() {
assert_kube_resource::<ServiceAccount>();
}
#[test]
fn node_satisfies_kube_resource() {
assert_kube_resource::<Node>();
}
#[test]
fn cluster_role_satisfies_kube_resource() {
assert_kube_resource::<ClusterRole>();
}
#[test]
fn namespace_satisfies_kube_resource() {
assert_kube_resource::<Namespace>();
}
#[test]
fn pod_satisfies_namespaced_resource() {
assert_namespaced::<Pod>();
}
#[test]
fn configmap_satisfies_namespaced_resource() {
assert_namespaced::<ConfigMap>();
}
#[test]
fn secret_satisfies_namespaced_resource() {
assert_namespaced::<Secret>();
}
#[test]
fn service_account_satisfies_namespaced_resource() {
assert_namespaced::<ServiceAccount>();
}
#[test]
fn node_satisfies_cluster_resource() {
assert_cluster::<Node>();
}
#[test]
fn cluster_role_satisfies_cluster_resource() {
assert_cluster::<ClusterRole>();
}
#[test]
fn cluster_role_binding_satisfies_cluster_resource() {
assert_cluster::<ClusterRoleBinding>();
}
#[test]
fn namespace_satisfies_cluster_resource() {
assert_cluster::<Namespace>();
}
#[test]
fn pod_is_namespaced_not_cluster() {
assert_namespaced::<Pod>();
}
#[test]
fn node_is_cluster_not_namespaced() {
assert_cluster::<Node>();
}
#[test]
fn namespaced_resource_implies_kube_resource() {
assert_kube_resource::<Pod>();
assert_namespaced::<Pod>();
}
#[test]
fn cluster_resource_implies_kube_resource() {
assert_kube_resource::<Node>();
assert_cluster::<Node>();
}
mod synthetic {
use kube::core::ObjectMeta;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FakeCrd {
pub metadata: ObjectMeta,
}
impl kube::Resource for FakeCrd {
type DynamicType = ();
type Scope = k8s_openapi::NamespaceResourceScope;
fn group(_: &()) -> Cow<'_, str> {
Cow::Borrowed("example.com")
}
fn version(_: &()) -> Cow<'_, str> {
Cow::Borrowed("v1")
}
fn kind(_: &()) -> Cow<'_, str> {
Cow::Borrowed("FakeCrd")
}
fn plural(_: &()) -> Cow<'_, str> {
Cow::Borrowed("fakecrds")
}
fn meta(&self) -> &ObjectMeta {
&self.metadata
}
fn meta_mut(&mut self) -> &mut ObjectMeta {
&mut self.metadata
}
}
}
#[test]
fn user_defined_namespaced_crd_satisfies_kube_resource() {
assert_kube_resource::<synthetic::FakeCrd>();
}
#[test]
fn user_defined_namespaced_crd_satisfies_namespaced_resource() {
assert_namespaced::<synthetic::FakeCrd>();
}
}