|
| 1 | +--- |
| 2 | +title: Test-Set Configuration File (config.yaml) |
| 3 | +description: How to define per test-set configuration (like overriding appCommand) using config.yaml placed alongside mock.yaml. |
| 4 | +--- |
| 5 | + |
| 6 | +# Test-Set Configuration File |
| 7 | + |
| 8 | +Each Keploy test-set can have its own lightweight configuration file. Create a file named `config.yaml` in the **same directory** as the corresponding `mock.yaml` (and any captured test data). This lets you override runtime parameters (like the application start command) or supply per test-set scripts/metadata without affecting other sets. |
| 9 | + |
| 10 | +## File Location |
| 11 | + |
| 12 | +``` |
| 13 | +tests/ |
| 14 | + my-test-set/ |
| 15 | + mock.yaml # Recorded mocks for this test-set |
| 16 | + config.yaml # Test-set specific configuration (optional) |
| 17 | + ... # Any other assets |
| 18 | +``` |
| 19 | + |
| 20 | +If `config.yaml` is absent, Keploy falls back to global/default settings. |
| 21 | + |
| 22 | +## Minimal Use Case: Override appCommand |
| 23 | + |
| 24 | +To run the application under test with a different command (env vars, flags, image, binary path, etc.) only for this test-set, place a `config.yaml` beside `mock.yaml` containing just the `appCommand` key: |
| 25 | + |
| 26 | +```yaml |
| 27 | +appCommand: docker run --rm --name python-api \ |
| 28 | + --network python-api-network \ |
| 29 | + -e DATABASE_URL=mysql+pymysql://user:password@mysql-db:3306/fastapi_db \ |
| 30 | + -e SECRET_KEY=super-secret-key-for-testing \ |
| 31 | + -e ACCESS_TOKEN_EXPIRE_MINUTES=5 \ |
| 32 | + -p 8000:8000 python-rest-api |
| 33 | +``` |
| 34 | + |
| 35 | +That’s all you need when your only goal is to override how the app starts during replay for this specific test-set. |
| 36 | + |
| 37 | +## Available (Optional) Keys |
| 38 | + |
| 39 | +You can extend `config.yaml` later if needed. Common fields (all optional unless noted): |
| 40 | + |
| 41 | +common example - |
| 42 | + |
| 43 | +```yaml |
| 44 | +preScript: "" |
| 45 | +postScript: "" |
| 46 | +template: {} |
| 47 | +mockRegistry: null |
| 48 | +appCommand: <my test-set specific app command> |
| 49 | +metadata: |
| 50 | + name: flask-mysql-app |
| 51 | +``` |
| 52 | +
|
| 53 | +| Key | Purpose | |
| 54 | +| -------------- | -------------------------------------------------------------------------------------------------------------------------- | |
| 55 | +| `appCommand` | Command Keploy should run to start the application for this test-set. Overrides any global/app-level command. | |
| 56 | +| `preScript` | Shell script (inline or path) executed before starting the app / replaying tests. Use for seeding DB, cleaning state, etc. | |
| 57 | +| `postScript` | Shell script executed after tests finish (cleanup, exporting artifacts). | |
| 58 | +| `mockId` | Explicit identifier if you maintain multiple mock groups in the same folder and need disambiguation. | |
| 59 | +| `template` | A map/object for advanced templating or variable substitution (future/advanced usage). | |
| 60 | +| `mockRegistry` | (Optional) Registry or remote reference for fetching mocks if they aren’t local. | |
| 61 | +| `metadata` | Arbitrary informational fields (e.g., `name`, `owner`, `tags`). Non-functional but useful for organization. | |
| 62 | + |
| 63 | +> Note: Only include the keys you actually need. Unused keys can be omitted entirely. |
| 64 | + |
| 65 | +## Tips & Best Practices |
| 66 | + |
| 67 | +1. Keep the minimal override: if you only change the start command, only keep `appCommand`—simpler diffs and fewer merge conflicts. |
| 68 | +2. Avoid storing secrets directly; prefer referencing environment files or secret managers. |
| 69 | +3. Use descriptive `metadata.name` to make CI logs clearer when multiple test-sets run. |
| 70 | +4. Validate the command manually once before relying on it in automated replay. |
| 71 | + |
| 72 | +## Troubleshooting |
| 73 | + |
| 74 | +| Symptom | Likely Cause | Fix | |
| 75 | +| ----------------------------------- | ------------------------------------------------------------------- | --------------------------------------------------------- | |
| 76 | +| App doesn’t start for this test-set | Typo in `appCommand` or missing image | Run the command locally; ensure image/tag exists. | |
| 77 | +| Pre/post script not executed | Wrong key name (`preScript`/`postScript`) or YAML indentation error | Validate YAML (e.g., with `yamllint`) and check spelling. | |
| 78 | +| Wrong mocks used | Missing/incorrect `mockId` when multiple sets present | Add/adjust `mockId` or standardize directory structure. | |
| 79 | + |
| 80 | +## Quick Validation Checklist |
| 81 | + |
| 82 | +- `config.yaml` sits beside `mock.yaml`. |
| 83 | +- YAML parses (`yamllint config.yaml`). |
| 84 | +- Only necessary keys included. |
| 85 | +- `appCommand` works standalone in your shell. |
| 86 | + |
| 87 | +--- |
0 commit comments