Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add integration tests for store import and tuple write/delete #390

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ dist/

# Mock source files
/mocks

# Test files
/tests/fixtures/identifiers
8 changes: 8 additions & 0 deletions tests/fixtures/basic-model.fga
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
model
schema 1.1

type user

type group
relations
define owner: [user]
10 changes: 10 additions & 0 deletions tests/fixtures/basic-store.fga.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: Basic 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
7 changes: 7 additions & 0 deletions tests/fixtures/basic-tuples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"user": "user:anne",
"relation": "owner",
"object": "group:foo"
}
]
10 changes: 10 additions & 0 deletions tests/import-tests-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
config:
inherit-env: true

tests:
001 - it successfully imports a store:
command: fga store import --file=./tests/fixtures/basic-store.fga.yaml --max-parallel-requests=1 --max-tuples-per-write=1
exit-code: 0
stdout:
json:
store.name: "Basic Store"
2 changes: 2 additions & 0 deletions tests/scripts/run-test-suites.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ exit_code=$?
docker stop openfga-cli-tests
docker rm openfga-cli-tests

rm -rf tests/fixtures/identifiers

exit $exit_code
22 changes: 22 additions & 0 deletions tests/scripts/test-data/get-model-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#! /bin/bash

FILE=./tests/fixtures/identifiers/model-id
if [ -f "$FILE" ]; then
cat $FILE
exit 0
fi

STORE_ID=""
STORE_FILE=./tests/fixtures/identifiers/store-id
if [ -f "$STORE_FILE" ]; then
STORE_ID=$( cat $STORE_FILE )
else
echo "no store created, must create a store before a model"
exit 1
fi

model=$( fga model write --file=./tests/fixtures/basic-model.fga --store-id="$STORE_ID" )

mkdir -p ./tests/fixtures/identifiers
echo "$model" | jq -r ".authorization_model_id" > $FILE
cat $FILE
13 changes: 13 additions & 0 deletions tests/scripts/test-data/get-store-id.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#! /bin/bash

FILE=./tests/fixtures/identifiers/store-id
if [ -f "$FILE" ]; then
cat $FILE
exit 0
fi

store=$( fga store create --name "integration-test-store" )

mkdir -p ./tests/fixtures/identifiers
echo "$store" | jq -r ".store.id" > $FILE
cat $FILE
16 changes: 16 additions & 0 deletions tests/tuple-test-cases.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
config:
inherit-env: true

tests:
001 - it successfully writes tuples to a store:
command: fga tuple write --file=./tests/fixtures/basic-tuples.json --max-tuples-per-write=1 --max-parallel-requests=1 --store-id=$(./tests/scripts/test-data/get-store-id.sh) --model-id=$(./tests/scripts/test-data/get-model-id.sh)
exit-code: 0
stdout:
json:
successful.0.user: "user:anne"
002 - it successfully deletes tuples from a store:
command: fga tuple delete --file=./tests/fixtures/basic-tuples.json --max-tuples-per-write=1 --max-parallel-requests=1 --store-id=$(./tests/scripts/test-data/get-store-id.sh) --model-id=$(./tests/scripts/test-data/get-model-id.sh)
exit-code: 0
stdout:
json:
successful.0.user: "user:anne"
Loading