From ec6b43200c8b5aac875dcde44fb2a2a3baceb05c Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 5 Nov 2025 14:21:57 +0000 Subject: [PATCH 1/2] test: add integration tests to cover different path variants in model test and store import --- .../relative-path-store.fga.yaml | 10 ++++++++++ tests/import-tests-cases.yaml | 6 ++++++ tests/model-test-cases.yaml | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/fixtures/relative-path/relative-path-store.fga.yaml create mode 100644 tests/model-test-cases.yaml diff --git a/tests/fixtures/relative-path/relative-path-store.fga.yaml b/tests/fixtures/relative-path/relative-path-store.fga.yaml new file mode 100644 index 00000000..08236db4 --- /dev/null +++ b/tests/fixtures/relative-path/relative-path-store.fga.yaml @@ -0,0 +1,10 @@ +name: Relative Path Store +model_file: ../basic-model.fga +tuple_file: ../basic-tuples.json +tests: + - name: test-1 + check: + - user: user:anne + object: group:foo + assertions: + owner: true \ No newline at end of file diff --git a/tests/import-tests-cases.yaml b/tests/import-tests-cases.yaml index 565054b2..42be315e 100644 --- a/tests/import-tests-cases.yaml +++ b/tests/import-tests-cases.yaml @@ -8,3 +8,9 @@ tests: stdout: json: store.name: "Basic Store" + 002 - it successfully imports a store with relative paths: + command: fga store import --file=./tests/fixtures/relative-path/relative-path-store.fga.yaml + exit-code: 0 + stdout: + json: + store.name: "Relative Path Store" diff --git a/tests/model-test-cases.yaml b/tests/model-test-cases.yaml new file mode 100644 index 00000000..c830cf4d --- /dev/null +++ b/tests/model-test-cases.yaml @@ -0,0 +1,20 @@ +config: + inherit-env: true + +tests: + 001 - it successfully runs local tests against a store with an absolute path: + command: fga model test --tests ./tests/fixtures/basic-store.fga.yaml + exit-code: 0 + stderr: # Test Summary # + 002 - it successfully runs local tests against a store with a relative path: + command: fga model test --tests tests/fixtures/basic-store.fga.yaml + exit-code: 0 + stderr: # Test Summary # + 003 - it successfully runs local tests against a store when resolving a glob pattern: + command: fga model test --tests "tests/**/*-store.fga.yaml" + exit-code: 0 + stderr: # Test Summary # + 004 - it successfully runs local tests against a store with relative paths in the store file: + command: fga model test --tests tests/fixtures/relative-path/relative-path-store.fga.yaml + exit-code: 0 + stderr: # Test Summary # From 1033c1bbfa286547f41059f70ef1b5948edf07e6 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 5 Nov 2025 14:40:43 +0000 Subject: [PATCH 2/2] fix(model/test): dont attempt to resolve store files against a basepath as they are already complete --- cmd/model/test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/model/test.go b/cmd/model/test.go index 4226c464..70ac232d 100644 --- a/cmd/model/test.go +++ b/cmd/model/test.go @@ -19,7 +19,6 @@ package model import ( "fmt" "os" - "path" "path/filepath" "strings" @@ -77,7 +76,7 @@ var modelTestCmd = &cobra.Command{ summaries := []string{} for _, file := range fileNames { - format, storeData, err := storetest.ReadFromFile(file, path.Dir(file)) + format, storeData, err := storetest.ReadFromFile(file, "") if err != nil { return fmt.Errorf("failed to read test file %s: %w", file, err) }