Skip to content

Commit d2758e5

Browse files
Feature/integration tests 7 (#21)
* feat: add integration tests with docker-compose (#7) - wait-for, render, fetch, exec, seed PostgreSQL/MySQL with cross-table refs, idempotency, reset, create database/schema, create-if-missing tests * fix: use inline escaped values in postgres insert_row/row_exists to fix TEXT-to-INTEGER coercion * fix: reverse seed set order during reset to respect foreign key constraints * fix: separate reset (reverse) and seed (forward) passes for FK-safe reset mode * refactor: remove placeholder seed_sets from test specs and move inline seed specs to files * Update .github/workflows/integration.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix: PostgreSQL insert_row fails for tables with text primary keys (#22) The insert_row function always used RETURNING COALESCE(CAST(id AS BIGINT), 0) even when no auto_id_column was specified, defaulting to the id column. For tables with text primary keys (like NetBird's accounts, users, groups), CAST to BIGINT fails with a generic db error. Fix: Only use RETURNING clause when auto_id_column is explicitly set. When no auto_id is needed, use a simple INSERT without RETURNING. * fix: address PR #21 review comments - remove unused CI client install, add cfg feature guards, fix README test name, document escaped literals rationale, reword CHANGELOG --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent ee3fd56 commit d2758e5

15 files changed

Lines changed: 133 additions & 78 deletions

.github/workflows/integration.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,6 @@ jobs:
5151
- uses: actions/checkout@v4
5252
- uses: dtolnay/rust-toolchain@stable
5353
- uses: Swatinem/rust-cache@v2
54-
- name: Install psql and mysql clients
55-
run: |
56-
sudo apt-get update -qq
57-
sudo apt-get install -y -qq postgresql-client default-mysql-client
5854
- name: Run integration tests
5955
env:
6056
INTEGRATION: "1"

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
- Clarified that seed phases with only `create_if_missing` can omit the `seed_sets` field entirely (`seed_sets` defaults to empty via `#[serde(default)]`); updated integration test YAML specs accordingly
12+
1013
### Added
1114
- Integration tests with docker-compose for end-to-end testing against real Postgres 16, MySQL 8.0, and nginx services (`tests/integration_test.rs`): wait-for TCP/HTTP/timeout/multiple targets, render template, fetch HTTP, exec command, seed PostgreSQL and MySQL with cross-table reference verification, create database/schema, idempotency, and reset mode
1215
- Additional create-if-missing integration tests: 2 PostgreSQL and 2 MySQL tests using known non-existing database names (`initium_noexist_alpha`, `initium_noexist_beta`) to verify database creation, existence checks, and idempotent re-runs
1316
- `tests/docker-compose.yml` with Postgres, MySQL, and HTTP health-check server definitions
14-
- `tests/fixtures/` with seed spec files and template for integration tests
17+
- `tests/input/` with seed spec files and template for integration tests
1518
- Separate GitHub Actions workflow (`.github/workflows/integration.yml`) for integration tests with service containers
1619
- Helm chart unit tests using helm-unittest plugin (`charts/initium/tests/deployment_test.yaml`) covering deployment rendering, securityContext enforcement, disabled sampleDeployment, multiple initContainers, extraVolumes/extraVolumeMounts, image configuration, workdir mount, and labels
1720
- `helm unittest` step added to CI helm-lint job with automatic plugin installation

src/seed/db.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,11 @@ impl Database for PostgresDb {
307307
Ok(())
308308
}
309309

310+
// Seed values are untyped strings that may target columns of any type
311+
// (INTEGER, TEXT, etc.). Parameterized queries with $N send values as
312+
// TEXT, which postgres cannot implicitly cast to other types. String
313+
// literals have type `unknown` and auto-cast to the target column type,
314+
// so we use escaped literals here. Identifiers are still sanitized.
310315
fn insert_row(
311316
&mut self,
312317
table: &str,

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ docker compose -f tests/docker-compose.yml down
3030
| `test_waitfor_tcp_postgres` | wait-for TCP against Postgres succeeds |
3131
| `test_waitfor_tcp_mysql` | wait-for TCP against MySQL succeeds |
3232
| `test_waitfor_http_server` | wait-for HTTP against nginx returns 200 |
33-
| `test_waitfor_nonexistent_service` | wait-for against closed port fails with exit code 1 |
33+
| `test_waitfor_nonexistent_service_timeout` | wait-for against closed port fails with exit code 1 |
3434
| `test_waitfor_multiple_targets` | wait-for with Postgres + MySQL + HTTP all reachable |
3535
| `test_render_template` | render envsubst template produces correct output |
3636
| `test_fetch_from_http_server` | fetch from nginx writes HTML to file |

tests/input/create-db-mysql.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
database:
2+
driver: mysql
3+
url_env: MYSQL_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_db
8+
order: 1
9+
database: initium_created_db
10+
create_if_missing: true
11+
seed_sets:
12+
- name: placeholder
13+
tables:
14+
- table: products
15+
rows: []
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
database:
2+
driver: postgres
3+
url_env: POSTGRES_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_db
8+
order: 1
9+
database: initium_created_db
10+
create_if_missing: true
11+
seed_sets:
12+
- name: placeholder
13+
tables:
14+
- table: departments
15+
rows: []
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
database:
2+
driver: mysql
3+
url_env: MYSQL_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_alpha
8+
order: 1
9+
database: initium_noexist_alpha
10+
create_if_missing: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
database:
2+
driver: postgres
3+
url_env: POSTGRES_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_alpha
8+
order: 1
9+
database: initium_noexist_alpha
10+
create_if_missing: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
database:
2+
driver: mysql
3+
url_env: MYSQL_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_beta
8+
order: 1
9+
database: initium_noexist_beta
10+
create_if_missing: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
database:
2+
driver: postgres
3+
url_env: POSTGRES_URL
4+
tracking_table: initium_seed
5+
6+
phases:
7+
- name: create_beta
8+
order: 1
9+
database: initium_noexist_beta
10+
create_if_missing: true

0 commit comments

Comments
 (0)