-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add integration tests for store import and tuple write/delete
This is the first example of how we can potentially create and reuse stores and models between tests based on the learnings from Auth0 CLI testing.
- Loading branch information
1 parent
34fa32f
commit 245acc8
Showing
9 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,6 @@ dist/ | |
|
||
# Mock source files | ||
/mocks | ||
|
||
# Test files | ||
/tests/fixtures/identifiers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[ | ||
{ | ||
"user": "user:anne", | ||
"relation": "owner", | ||
"object": "group:foo" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |