#[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};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct FakeCrd {
pub metadata: ObjectMeta,
}
impl k8s_openapi::Resource for FakeCrd {
const API_VERSION: &'static str = "example.com/v1";
const GROUP: &'static str = "example.com";
const KIND: &'static str = "FakeCrd";
const VERSION: &'static str = "v1";
const URL_PATH_SEGMENT: &'static str = "fakecrds";
type Scope = k8s_openapi::NamespaceResourceScope;
}
impl k8s_openapi::Metadata for FakeCrd {
type Ty = ObjectMeta;
fn metadata(&self) -> &ObjectMeta {
&self.metadata
}
fn metadata_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>();
}
}