# Service Proxy - SkyWalking Infra E2E (KinD)

This directory contains end-to-end tests for `service-proxy` using
[apache/skywalking-infra-e2e](https://github.com/apache/skywalking-infra-e2e) with a KinD cluster.

## Prerequisites

- Docker
- kind
- kubectl
- python3
- `e2e` CLI (SkyWalking Infra E2E)

## How it works

`test/e2e/e2e.yaml` describes a full test workflow:

1. **setup (kind)**:
   - Creates a KinD cluster using `test/e2e/kind.yaml`.
   - Imports locally-built Docker images into the cluster:
     - `service-proxy:e2e`
     - `mock-server:e2e`
   - Applies Kubernetes manifests under `test/e2e/manifests/`.
   - Exposes `deployment/service-proxy` port `8080` to localhost (the framework exports the host/port as env vars).
2. **trigger (http)**:
   - Sends repeated HTTP requests to `/healthz` to warm up and ensure the service is reachable.
3. **verify**:
   - Each `verify.cases[].query` is executed via `bash -e` and must print **YAML** to stdout.
   - The query is executed in the directory where you run `e2e run` (this repo assumes `internal/service-proxy/`).
   - The output YAML is compared with an `expected` file under `test/e2e/expected/`.
   - Expected files are **Go templates**, so you can write flexible assertions (e.g. `notEmpty`, `regexp`, `contains`)
     instead of strict string equality.

## Run locally

Run from `internal/service-proxy/`:

```bash
make e2e-images
make e2e-run
```

Notes:

- `setup.kind.import-images` requires the images to exist locally before `e2e run`.
- By default, `cleanup.on: success` deletes the KinD cluster after a successful run.
  If you need to debug failures, change it to `never` temporarily.

## Add a new case

1. Add a new entry to `verify.cases` in `test/e2e/e2e.yaml`.
2. Make sure the `query` prints YAML to stdout (do not print logs/noise).
   - Prefer putting larger logic into `test/e2e/scripts/*.py` and call it from the query.
3. Add an `expected` template under `test/e2e/expected/`.
   - Use template helpers like `contains` for unordered lists or non-deterministic fields.

Tip: you can run with `e2e -v debug run -c test/e2e/e2e.yaml` and use `--work-dir` to inspect generated logs/artifacts.
