Skip to content

Commit db7dfeb

Browse files
authored
fix(model/test): dont attempt to resolve store files against a basepath as they are already complete (#603)
* test: add integration tests to cover different path variants in model test and store import * fix(model/test): dont attempt to resolve store files against a basepath as they are already complete
1 parent d5566a9 commit db7dfeb

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

cmd/model/test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package model
1919
import (
2020
"fmt"
2121
"os"
22-
"path"
2322
"path/filepath"
2423
"strings"
2524

@@ -77,7 +76,7 @@ var modelTestCmd = &cobra.Command{
7776
summaries := []string{}
7877

7978
for _, file := range fileNames {
80-
format, storeData, err := storetest.ReadFromFile(file, path.Dir(file))
79+
format, storeData, err := storetest.ReadFromFile(file, "")
8180
if err != nil {
8281
return fmt.Errorf("failed to read test file %s: %w", file, err)
8382
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: Relative Path Store
2+
model_file: ../basic-model.fga
3+
tuple_file: ../basic-tuples.json
4+
tests:
5+
- name: test-1
6+
check:
7+
- user: user:anne
8+
object: group:foo
9+
assertions:
10+
owner: true

tests/import-tests-cases.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ tests:
88
stdout:
99
json:
1010
store.name: "Basic Store"
11+
002 - it successfully imports a store with relative paths:
12+
command: fga store import --file=./tests/fixtures/relative-path/relative-path-store.fga.yaml
13+
exit-code: 0
14+
stdout:
15+
json:
16+
store.name: "Relative Path Store"

tests/model-test-cases.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
config:
2+
inherit-env: true
3+
4+
tests:
5+
001 - it successfully runs local tests against a store with an absolute path:
6+
command: fga model test --tests ./tests/fixtures/basic-store.fga.yaml
7+
exit-code: 0
8+
stderr: # Test Summary #
9+
002 - it successfully runs local tests against a store with a relative path:
10+
command: fga model test --tests tests/fixtures/basic-store.fga.yaml
11+
exit-code: 0
12+
stderr: # Test Summary #
13+
003 - it successfully runs local tests against a store when resolving a glob pattern:
14+
command: fga model test --tests "tests/**/*-store.fga.yaml"
15+
exit-code: 0
16+
stderr: # Test Summary #
17+
004 - it successfully runs local tests against a store with relative paths in the store file:
18+
command: fga model test --tests tests/fixtures/relative-path/relative-path-store.fga.yaml
19+
exit-code: 0
20+
stderr: # Test Summary #

0 commit comments

Comments
 (0)