use super::*;
use test_util::prelude::sim_assert_eq;
fn resource(api_version: &str, kind: &str) -> ResourceRef {
ResourceRef::concrete(api_version.to_string(), kind.to_string())
}
#[test]
fn third_party_crds_yield_relative_path() {
let r = resource("monitoring.coreos.com/v1", "ServiceMonitor");
sim_assert_eq!(
have: relative_path_for_resource(&r),
want: Some("monitoring.coreos.com/servicemonitor_v1.json".to_string())
);
}
#[test]
fn k8s_io_family_is_excluded_from_crd_catalog() {
for (api_version, kind) in [
("networking.k8s.io/v1", "Ingress"),
("networking.k8s.io/v1", "NetworkPolicy"),
("rbac.authorization.k8s.io/v1", "Role"),
("rbac.authorization.k8s.io/v1", "RoleBinding"),
("rbac.authorization.k8s.io/v1", "ClusterRole"),
("rbac.authorization.k8s.io/v1", "ClusterRoleBinding"),
("storage.k8s.io/v1", "StorageClass"),
("coordination.k8s.io/v1", "Lease"),
("events.k8s.io/v1", "Event"),
(
"admissionregistration.k8s.io/v1",
"ValidatingWebhookConfiguration",
),
("apiextensions.k8s.io/v1", "CustomResourceDefinition"),
] {
sim_assert_eq!(
have: relative_path_for_resource(&resource(api_version, kind)),
want: None,
"{api_version}/{kind} must NOT be routed to the CRD catalog"
);
}
}
#[test]
fn legacy_short_groups_are_excluded() {
for (api_version, kind) in [
("apps/v1", "Deployment"),
("batch/v1", "Job"),
("autoscaling/v2", "HorizontalPodAutoscaler"),
("policy/v1", "PodDisruptionBudget"),
("policy/v1beta1", "PodSecurityPolicy"),
("extensions/v1beta1", "DaemonSet"),
] {
sim_assert_eq!(
have: relative_path_for_resource(&resource(api_version, kind)),
want: None,
"{api_version}/{kind} must NOT be routed to the CRD catalog"
);
}
}
#[test]
fn k8s_io_crd_groups_yield_relative_path() {
sim_assert_eq!(
have: relative_path_for_resource(&resource("autoscaling.k8s.io/v1", "VerticalPodAutoscaler")),
want: Some("autoscaling.k8s.io/verticalpodautoscaler_v1.json".to_string())
);
sim_assert_eq!(
have: relative_path_for_resource(&resource("gateway.networking.k8s.io/v1", "HTTPRoute")),
want: Some("gateway.networking.k8s.io/httproute_v1.json".to_string())
);
sim_assert_eq!(
have: relative_path_for_resource(&resource("gateway.networking.k8s.io/v1", "Gateway")),
want: Some("gateway.networking.k8s.io/gateway_v1.json".to_string())
);
sim_assert_eq!(
have: relative_path_for_resource(&resource("snapshot.storage.k8s.io/v1", "VolumeSnapshot")),
want: Some("snapshot.storage.k8s.io/volumesnapshot_v1.json".to_string())
);
}