mod common;
use common::{missing, Repo};
const DEPLOY: &str = "apiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: d\n";
#[test]
fn argo_ignores_yaml_outside_the_k8s_prefixes() {
let r = Repo::new();
r.stage("src/config.yaml", "kind: Workflow\n");
assert!(r.hook("pre-commit-argo-lint", &[]).silent());
}
#[test]
fn argo_ignores_k8s_yaml_that_is_not_a_workflow() {
let r = Repo::new();
r.stage("kubernetes/app/deploy.yaml", DEPLOY);
assert!(r.hook("pre-commit-argo-lint", &[]).silent());
}
#[test]
fn argo_recognises_every_workflow_kind() {
for kind in [
"Workflow",
"CronWorkflow",
"WorkflowTemplate",
"ClusterWorkflowTemplate",
] {
let r = Repo::new();
r.stage(
&format!("kubernetes/wf/{kind}.yaml"),
&format!("kind: {kind}\n"),
);
assert!(
!r.hook("pre-commit-argo-lint", &[]).silent(),
"{kind} was not picked up"
);
}
}
#[test]
fn argo_soft_fails_without_the_cli() {
if !missing("argo") {
println!(" ! argo PRESENT — skipping (this case asserts the ABSENT branch)");
return; }
let r = Repo::new();
r.stage("kubernetes/wf/w.yaml", "kind: Workflow\n");
let run = r.hook("pre-commit-argo-lint", &[]);
assert!(run.passed(), "a missing toolchain must not block a commit");
assert!(run.says("install"));
}
#[test]
fn kube_linter_ignores_yaml_outside_the_k8s_prefixes() {
let r = Repo::new();
r.stage("src/app.yaml", DEPLOY);
assert!(r.hook("pre-commit-kube-linter", &[]).silent());
}
#[test]
fn kube_linter_is_silent_without_a_config() {
let r = Repo::new();
r.stage("kubernetes/app/deploy.yaml", DEPLOY);
let run = r.hook("pre-commit-kube-linter", &[]);
assert!(run.passed());
assert!(
run.silent(),
"a repo that never opted in must hear nothing:\n{}",
run.output()
);
assert!(
!run.says("install"),
"nagged a repo that never opted in:\n{}",
run.output()
);
}
#[test]
fn kubeconform_ignores_yaml_outside_the_k8s_prefixes() {
let r = Repo::new();
r.stage("src/app.yaml", DEPLOY);
assert!(r.hook("pre-commit-kubeconform", &[]).silent());
}
#[test]
fn kubeconform_is_silent_with_no_kustomization_root() {
let r = Repo::new();
r.stage("kubernetes/loose/deploy.yaml", DEPLOY);
assert!(r.hook("pre-commit-kubeconform", &[]).silent());
}
#[test]
fn kubeconform_finds_a_root_above_the_staged_file() {
let r = Repo::new();
r.stage(
"kubernetes/app/base/kustomization.yaml",
"resources:\n - deploy.yaml\n",
);
r.stage("kubernetes/app/base/deploy.yaml", DEPLOY);
assert!(
!r.hook("pre-commit-kubeconform", &[]).silent(),
"the root above the file was not discovered"
);
}