|
1 | 1 | # Testing |
2 | 2 |
|
3 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). |
| 4 | + |
| 5 | +## Quick Start for Local Testing |
| 6 | + |
| 7 | +### Prerequisites |
| 8 | + |
| 9 | +- **Chef Workstation**: Install from [Chef Downloads](https://www.chef.io/downloads/tools/workstation) |
| 10 | +- **Docker**: Required for Dokken driver (faster local testing) |
| 11 | + - macOS: [Docker Desktop](https://www.docker.com/products/docker-desktop) |
| 12 | + - Linux: Install via package manager |
| 13 | + |
| 14 | +### Setup |
| 15 | + |
| 16 | +1. **Enable Dokken driver** (faster than Vagrant): |
| 17 | + |
| 18 | + ```bash |
| 19 | + export KITCHEN_LOCAL_YAML=kitchen.dokken.yml |
| 20 | + ``` |
| 21 | + |
| 22 | + Or add to your shell profile (`~/.bashrc`, `~/.zshrc`, or use `mise.toml`): |
| 23 | + |
| 24 | + ```bash |
| 25 | + echo 'export KITCHEN_LOCAL_YAML=kitchen.dokken.yml' >> ~/.zshrc |
| 26 | + ``` |
| 27 | + |
| 28 | +2. **Verify setup**: |
| 29 | + |
| 30 | + ```bash |
| 31 | + kitchen list |
| 32 | + ``` |
| 33 | + |
| 34 | + You should see Dokken as the driver for all instances. |
| 35 | + |
| 36 | +### Running Tests |
| 37 | + |
| 38 | +#### Run a single suite on one platform |
| 39 | + |
| 40 | +```bash |
| 41 | +kitchen test ident-16-debian-12 |
| 42 | +``` |
| 43 | + |
| 44 | +#### Run all platforms for a suite |
| 45 | + |
| 46 | +```bash |
| 47 | +kitchen test ident-16 |
| 48 | +``` |
| 49 | + |
| 50 | +#### Run specific suite on multiple platforms for verification |
| 51 | + |
| 52 | +```bash |
| 53 | +kitchen test ident-16-debian-12 ident-16-ubuntu-2204 ident-16-rockylinux-9 |
| 54 | +``` |
| 55 | + |
| 56 | +#### Debug a failing test |
| 57 | + |
| 58 | +```bash |
| 59 | +# Create and converge the instance |
| 60 | +kitchen converge ident-16-debian-12 |
| 61 | + |
| 62 | +# Login to inspect |
| 63 | +kitchen login ident-16-debian-12 |
| 64 | + |
| 65 | +# Inside the container, check PostgreSQL status |
| 66 | +systemctl status postgresql-16 |
| 67 | +cat /var/lib/pgsql/16/data/pg_ident.conf |
| 68 | +cat /var/lib/pgsql/16/data/pg_hba.conf |
| 69 | +tail -f /var/lib/pgsql/16/data/log/postgresql-*.log |
| 70 | + |
| 71 | +# Run tests manually |
| 72 | +kitchen verify ident-16-debian-12 |
| 73 | + |
| 74 | +# Cleanup when done |
| 75 | +kitchen destroy ident-16-debian-12 |
| 76 | +``` |
| 77 | + |
| 78 | +### Troubleshooting |
| 79 | + |
| 80 | +#### Docker permission errors |
| 81 | + |
| 82 | +```bash |
| 83 | +# Linux: Add your user to docker group |
| 84 | +sudo usermod -aG docker $USER |
| 85 | +# Then logout and login again |
| 86 | +``` |
| 87 | + |
| 88 | +#### Kitchen hangs or fails to start |
| 89 | + |
| 90 | +```bash |
| 91 | +# Clean up old containers |
| 92 | +docker ps -a | grep kitchen | awk '{print $1}' | xargs docker rm -f |
| 93 | + |
| 94 | +# Clean up dokken network |
| 95 | +docker network prune |
| 96 | +``` |
| 97 | + |
| 98 | +#### Tests pass locally but fail in CI |
| 99 | + |
| 100 | +- Ensure you're using the same PostgreSQL version (check `node['test']['pg_ver']`) |
| 101 | +- Check platform differences (RHEL vs Debian package names, paths) |
| 102 | +- Review CI logs for specific error messages |
| 103 | + |
| 104 | +### Test Suite Overview |
| 105 | + |
| 106 | +- **access-\***: Tests `postgresql_access` resource (pg_hba.conf management) |
| 107 | +- **client-install-\***: Tests client-only installation |
| 108 | +- **extension-\***: Tests PostgreSQL extension installation |
| 109 | +- **ident-\***: Tests `postgresql_ident` resource (pg_ident.conf management) |
| 110 | +- **initdb-locale-\***: Tests database initialization with custom locale |
| 111 | +- **server-install-\***: Tests full server installation |
| 112 | +- **all-repos-install-\***: Tests installation with all repository options enabled |
| 113 | +- **no-repos-install-\***: Tests installation without PGDG repositories |
| 114 | +- **repo-\***: Tests repository configuration only |
0 commit comments