From 91ce94ee1e861c64ee31935f480c8550472b8bee Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Thu, 8 Oct 2026 16:34:13 +0100 Subject: [PATCH] refactor(tests): split mapping-test-cases.yaml by subcommand mapping-test-cases.yaml covered all four mapping subcommands in one file. Splits it into one file per subcommand so each is independently scannable and failures are immediately attributable. Commander discovers all YAML files in tests/ via --dir, so no runner changes are needed. --- ....yaml => mapping-evaluate-test-cases.yaml} | 108 +++--------------- tests/mapping-init-test-cases.yaml | 17 +++ tests/mapping-test-test-cases.yaml | 31 +++++ tests/mapping-validate-test-cases.yaml | 36 ++++++ 4 files changed, 99 insertions(+), 93 deletions(-) rename tests/{mapping-test-cases.yaml => mapping-evaluate-test-cases.yaml} (53%) create mode 100644 tests/mapping-init-test-cases.yaml create mode 100644 tests/mapping-test-test-cases.yaml create mode 100644 tests/mapping-validate-test-cases.yaml diff --git a/tests/mapping-test-cases.yaml b/tests/mapping-evaluate-test-cases.yaml similarity index 53% rename from tests/mapping-test-cases.yaml rename to tests/mapping-evaluate-test-cases.yaml index c8f7cc5a..c813fcc1 100644 --- a/tests/mapping-test-cases.yaml +++ b/tests/mapping-evaluate-test-cases.yaml @@ -2,86 +2,8 @@ config: inherit-env: true tests: - # fga mapping validate - 001 - validate accepts a valid mapping: - command: fga mapping validate ./tests/fixtures/basic-mapping.yaml - exit-code: 0 - stdout: - contains: - - "valid" - - 002 - validate json format reports rule count: - command: fga mapping validate --format json ./tests/fixtures/basic-mapping.yaml - exit-code: 0 - stdout: - json: - valid: "true" - rule_count: "1" - - 003 - validate rejects an invalid mapping: - command: fga mapping validate ./tests/fixtures/invalid-mapping.yaml - exit-code: 2 - stderr: - contains: - - "unclosed" - - 004 - validate json format reports errors on invalid mapping: - command: fga mapping validate --format json ./tests/fixtures/invalid-mapping.yaml - exit-code: 2 - stdout: - json: - valid: "false" - - 005 - validate rejects unknown format: - command: fga mapping validate --format xml ./tests/fixtures/basic-mapping.yaml - exit-code: 2 - - # fga mapping test - 006 - test runs passing tests: - command: fga mapping test --format json ./tests/fixtures/basic-mapping.yaml - exit-code: 0 - stdout: - json: - summary.total: "2" - summary.passed: "2" - summary.failed: "0" - - 007 - test compile error exits with code 2: - command: fga mapping test ./tests/fixtures/invalid-mapping.yaml - exit-code: 2 - - 008 - test --run filters by substring: - command: fga mapping test --format json --run anne ./tests/fixtures/basic-mapping.yaml - exit-code: 0 - stdout: - json: - summary.total: "2" - summary.passed: "1" - - 009 - test --run matching nothing exits non-zero: - command: fga mapping test --run NOMATCH ./tests/fixtures/basic-mapping.yaml - exit-code: 1 - stderr: - contains: - - "matched no tests" - - # fga mapping init - 010 - init creates a mapping file: - command: fga mapping init /tmp/fga-mapping-test-$$.yaml - exit-code: 0 - stdout: - contains: - - "Created" - - 011 - init --minimal creates file without tests block: - command: bash -c 'fga mapping init --minimal /tmp/fga-mapping-minimal-test-$$.yaml && cat /tmp/fga-mapping-minimal-test-$$.yaml' - exit-code: 0 - stdout: - not-contains: - - "tests:" - - # fga mapping evaluate (run is a deprecated alias) - 012 - evaluate emits JSONL tuple from stdin: + # run is a deprecated alias for evaluate + 001 - evaluate emits JSONL tuple from stdin: command: bash -c 'echo '"'"'{"id":"anne","org":"acme"}'"'"' | fga mapping evaluate ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: @@ -91,7 +13,7 @@ tests: relation: "member" object: "org:acme" - 013 - evaluate --writes-only emits ClientTupleKey shape without op or action field: + 002 - evaluate --writes-only emits ClientTupleKey shape without op or action field: command: bash -c 'echo '"'"'{"id":"anne","org":"acme"}'"'"' | fga mapping evaluate --writes-only ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: @@ -103,7 +25,7 @@ tests: - '"op"' - '"action"' - 014 - evaluate --input reads from file: + 003 - evaluate --input reads from file: command: fga mapping evaluate --input ./tests/fixtures/mapping-event.json ./tests/fixtures/basic-mapping.yaml exit-code: 0 stdout: @@ -111,32 +33,32 @@ tests: op: "write" user: "user:anne" - 015 - evaluate --format json --writes-only returns a flat array of tuples: + 004 - evaluate --format json --writes-only returns a flat array of tuples: command: bash -c 'echo '"'"'{"id":"anne","org":"acme"}'"'"' | fga mapping evaluate --format json --writes-only ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: json: 0.user: "user:anne" - 016 - evaluate --format json returns a batch object with writes: + 005 - evaluate --format json returns a batch object with writes: command: bash -c 'echo '"'"'{"id":"anne","org":"acme"}'"'"' | fga mapping evaluate --format json ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: json: writes.0.user: "user:anne" - 017 - evaluate rejects unknown format: + 006 - evaluate rejects unknown format: command: bash -c 'echo '"'"'{}'"'"' | fga mapping evaluate --format xml ./tests/fixtures/basic-mapping.yaml' exit-code: 2 - 018 - evaluate rejects invalid mapping: + 007 - evaluate rejects invalid mapping: command: bash -c 'echo '"'"'{}'"'"' | fga mapping evaluate ./tests/fixtures/invalid-mapping.yaml' exit-code: 2 stderr: contains: - "unclosed" - 019 - evaluate streams one op per record for multi-record input: + 008 - evaluate streams one op per record for multi-record input: command: bash -c 'printf '"'"'{"id":"anne","org":"acme"}\n{"id":"bob","org":"acme"}\n'"'"' | fga mapping evaluate ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: @@ -145,20 +67,20 @@ tests: - "user:anne" - "user:bob" - 020 - evaluate --aggregate dedups an identical tuple across records: + 009 - evaluate --aggregate dedups an identical tuple across records: command: bash -c 'printf '"'"'{"id":"anne","org":"acme"}\n{"id":"anne","org":"acme"}\n'"'"' | fga mapping evaluate --aggregate ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: line-count: 1 - 021 - evaluate --aggregate reports a cross-record write/delete conflict: + 010 - evaluate --aggregate reports a cross-record write/delete conflict: command: bash -c 'printf '"'"'{"id":"anne","org":"acme","op":"add"}\n{"id":"anne","org":"acme","op":"remove"}\n'"'"' | fga mapping evaluate --aggregate ./tests/fixtures/conflicting-mapping.yaml' exit-code: 1 stderr: contains: - "conflict" - 022 - evaluate --continue-on-error skips a malformed record and exits non-zero: + 011 - evaluate --continue-on-error skips a malformed record and exits non-zero: command: bash -c 'printf '"'"'{"id":"anne","org":"acme"}\nnot json\n{"id":"bob","org":"acme"}\n'"'"' | fga mapping evaluate --continue-on-error ./tests/fixtures/basic-mapping.yaml' exit-code: 1 stdout: @@ -170,20 +92,20 @@ tests: contains: - "skipping record on line 2" - 023 - evaluate --continue-on-error with all valid records exits zero: + 012 - evaluate --continue-on-error with all valid records exits zero: command: bash -c 'printf '"'"'{"id":"anne","org":"acme"}\n{"id":"bob","org":"acme"}\n'"'"' | fga mapping evaluate --continue-on-error ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: line-count: 2 - 024 - evaluate --aggregate dedups identical unresolved filters across records: + 013 - evaluate --aggregate dedups identical unresolved filters across records: command: bash -c 'printf '"'"'{"id":"anne","org":"acme"}\n{"id":"anne","org":"acme"}\n'"'"' | fga mapping evaluate --aggregate --format json ./tests/fixtures/filter-mapping.yaml' exit-code: 0 stdout: json: tuple_filter_operations.#: "1" - 025 - run alias prints deprecation warning and still produces output: + 014 - run alias prints deprecation warning and still produces output: command: bash -c 'echo '"'"'{"id":"anne","org":"acme"}'"'"' | fga mapping run ./tests/fixtures/basic-mapping.yaml' exit-code: 0 stdout: diff --git a/tests/mapping-init-test-cases.yaml b/tests/mapping-init-test-cases.yaml new file mode 100644 index 00000000..5f6ce3cc --- /dev/null +++ b/tests/mapping-init-test-cases.yaml @@ -0,0 +1,17 @@ +config: + inherit-env: true + +tests: + 001 - init creates a mapping file: + command: fga mapping init /tmp/fga-mapping-test-$$.yaml + exit-code: 0 + stdout: + contains: + - "Created" + + 002 - init --minimal creates file without tests block: + command: bash -c 'fga mapping init --minimal /tmp/fga-mapping-minimal-test-$$.yaml && cat /tmp/fga-mapping-minimal-test-$$.yaml' + exit-code: 0 + stdout: + not-contains: + - "tests:" diff --git a/tests/mapping-test-test-cases.yaml b/tests/mapping-test-test-cases.yaml new file mode 100644 index 00000000..128040b6 --- /dev/null +++ b/tests/mapping-test-test-cases.yaml @@ -0,0 +1,31 @@ +config: + inherit-env: true + +tests: + 001 - test runs passing tests: + command: fga mapping test --format json ./tests/fixtures/basic-mapping.yaml + exit-code: 0 + stdout: + json: + summary.total: "2" + summary.passed: "2" + summary.failed: "0" + + 002 - test compile error exits with code 2: + command: fga mapping test ./tests/fixtures/invalid-mapping.yaml + exit-code: 2 + + 003 - test --run filters by substring: + command: fga mapping test --format json --run anne ./tests/fixtures/basic-mapping.yaml + exit-code: 0 + stdout: + json: + summary.total: "2" + summary.passed: "1" + + 004 - test --run matching nothing exits non-zero: + command: fga mapping test --run NOMATCH ./tests/fixtures/basic-mapping.yaml + exit-code: 1 + stderr: + contains: + - "matched no tests" diff --git a/tests/mapping-validate-test-cases.yaml b/tests/mapping-validate-test-cases.yaml new file mode 100644 index 00000000..c6f8e002 --- /dev/null +++ b/tests/mapping-validate-test-cases.yaml @@ -0,0 +1,36 @@ +config: + inherit-env: true + +tests: + 001 - validate accepts a valid mapping: + command: fga mapping validate ./tests/fixtures/basic-mapping.yaml + exit-code: 0 + stdout: + contains: + - "valid" + + 002 - validate json format reports rule count: + command: fga mapping validate --format json ./tests/fixtures/basic-mapping.yaml + exit-code: 0 + stdout: + json: + valid: "true" + rule_count: "1" + + 003 - validate rejects an invalid mapping: + command: fga mapping validate ./tests/fixtures/invalid-mapping.yaml + exit-code: 2 + stderr: + contains: + - "unclosed" + + 004 - validate json format reports errors on invalid mapping: + command: fga mapping validate --format json ./tests/fixtures/invalid-mapping.yaml + exit-code: 2 + stdout: + json: + valid: "false" + + 005 - validate rejects unknown format: + command: fga mapping validate --format xml ./tests/fixtures/basic-mapping.yaml + exit-code: 2