Use Relative Path in `model_file` in Tests
When defining the location of the model_file in a test yaml file, the expected behaviour is that the path to the model_file is relative to the test file where it is referenced but seems to be relative to the directory where the command originated.
For example: I have a folder structure as below:
- src
- schema.fga
- tests
- tests.yaml
- data.yaml
In my tests.yaml file I define the location of the model_file as ../src/schema.fga.
If I execute this command:
fga model test --tests .\tests\tests.fga.yaml
from the root directory of the repo I get the below error:
Error: failed to read file ../src/schema.fga due to open ../src/schema.fga: The system cannot find the path specified.
If I execute the similar command:
fga model test --tests .\tests.fga.yaml then the command successfully executes.
Hi! I’m interested in taking on this issue. Can I go ahead and work on it?
Yes, I'm assigning it to you! Thanks!
Subject: Issue with CLI behavior – Unable to reproduce
Hi @aaguiarz ,
I’ve tested the issue by forking the repository, building and running the CLI as described. After reproducing the steps in a clean environment, I found that the behavior aligns with the expected output and the issue appears to be non-existent.
Here are the details I tested:
- downloaded your sample data with
git clone https://github.com/openfga/sample-stores.git openfga-sample-stores - reproduced the directory structure in the issue using your sample data (see below)
tree
.
├── src
│ ├── github.model.fga
│ └── model.fga
└── tests
├── github.store.fga.yaml
└── store.fga.yaml
2 directories, 4 files
- renamed the location of model files as described in the issue, i.e. relative to the test file
grep "model_file" tests/store.fga.yaml
model_file: ../src/model.fga
grep "model_file" tests/github.store.fga.yaml
model_file: ../src/github.model.fga
-
ran the command as described in the issue (ran multiple times from different locations showing only two different files as examples)
-
first example of expected/desired behaviour (works)
fga model test --tests ./tests/store.fga.yaml
# Test Summary #
Tests 3/3 passing
Checks 6/6 passing
ListObjects 1/1 passing
ListUsers 1/1 passing
- second example of expected/desired behaviour (works)
fga model test --tests ./tests/github.store.fga.yaml
# Test Summary #
Tests 4/4 passing
Checks 6/6 passing
ListObjects 1/1 passing
ListUsers 3/3 passing
- undesired behaviour (get error as expected)
fga model test --tests ./store.fga.yaml
Error: failed to read file ./store.fga.yaml due to open ./store.fga.yaml: no such file or directory
Please let me know if I misunderstood the issue or perhaps if there’s any additional context I should be aware of.
Best regards,
Denis
Hello @Denis-Kuso, just an FYI, I will be reassigning this issue to @SoulPancake, as he has opened a PR for this.