# cluster-agent E2E Tests

End-to-end tests for `cluster-agent` using [SkyWalking Infra E2E](https://github.com/apache/skywalking-infra-e2e).

## Prerequisites

- [KinD](https://kind.sigs.k8s.io/)
- [kubectl](https://kubernetes.io/docs/tasks/tools/)
- [SkyWalking Infra E2E](https://skywalking.apache.org/docs/skywalking-infra-e2e/latest/readme/) (`e2e` binary)
- Python 3 (for verification scripts)
- Docker

## Quick Start

```bash
# From internal/cluster-agent/
make e2e-images   # Build cluster-agent:e2e Docker image
make e2e-run      # Run the E2E suite (creates KinD cluster, deploys, verifies, cleans up)
```

## Test Cases

| Case | What it tests |
|------|---------------|
| `healthz-basic` | `/healthz` returns 200 with `SERVING` |
| `gateway-path-rewrite` | Gateway prefix path rewrite strips prefix correctly |
| `audit-log-check` | HTTP audit logs POST requests with sensitive fields redacted (`token`, `command`) |
| `audit-healthz-skip` | Healthz requests are excluded from audit logs |

## Structure

```
test/e2e/
├── e2e.yaml               # SkyWalking E2E config (setup/trigger/verify/cleanup)
├── kind.yaml              # KinD cluster definition
├── manifests/             # K8s manifests applied during setup
│   ├── 00-namespace.yaml
│   ├── 10-rbac.yaml
│   └── 20-cluster-agent.yaml
├── scripts/               # Python verification scripts
│   ├── healthz_check.py
│   ├── gateway_path_rewrite.py
│   ├── audit_log_extract.py
│   └── audit_healthz_skip.py
└── expected/              # Expected output templates (Go template syntax)
    ├── healthz-basic.yaml
    ├── gateway-path-rewrite.yaml
    ├── audit-log-check.yaml
    └── audit-healthz-skip.yaml
```

## Manual Run

```bash
# Build images first
make e2e-images

# Run with e2e CLI directly
e2e run -c test/e2e/e2e.yaml
```

Cleanup on failure is manual — delete the KinD cluster:

```bash
kind delete cluster --name e2e
```
