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

feat!: support multiple test files #8

Merged
merged 2 commits into from
Apr 4, 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
16 changes: 14 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@ name: Test Action

on:
workflow_dispatch:
pull_request:
types:
- opened
- edited
- synchronize

jobs:
test:
name: Run test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./
- name: default values
uses: ./
- name: specify folder
uses: ./
with:
store-file-path: ./example/model.fga.yaml
test_path: ./example
- name: single file
uses: ./
with:
test_path: ./example/model.fga.yaml
53 changes: 47 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,56 @@
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fopenfga%2Faction-openfga-test.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fopenfga%2Faction-openfga-test?ref=badge_shield)


This action can be used to test your authorization model using a store file.
This action can be used to test your authorization model using store test files.

## Parameter

| Parameter | Description |
|----------|--------------|
| `store-file-path` | The path to your store file relative to the root of your project |
| Parameter | Description | Required | Default |
|----------------------|----------------------------------------------------------------------------------|----------|--------------|
| `test_path` | The path to your store test file or folder relative to the root of your project. | No | `.` |
| `test_files_pattern` | The pattern to match test files. | No | `*.fga.yaml` |

## Example
> Note: the action will fail if no test is found in the specified test path with the given pattern


## Examples


### Running tests of `*.fga.yaml` files present in the repository

```yaml
name: Test Action

on:
workflow_dispatch:

jobs:
test:
name: Run test
runs-on: ubuntu-latest
steps:
- uses: openfga/[email protected]
```

### Running tests of `*.fga.yaml` files present in a given folder

```yaml
name: Test Action

on:
workflow_dispatch:

jobs:
test:
name: Run test
runs-on: ubuntu-latest
steps:
- uses: openfga/[email protected]
with:
test_path: example
```

### Running tests of a single file

```yaml
name: Test Action
Expand All @@ -25,7 +66,7 @@ jobs:
steps:
- uses: openfga/[email protected]
with:
store-file-path: ./example/model.fga.yaml
test_path: example/model.fga.yaml
```


Expand Down
24 changes: 20 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ branding:
color: 'green'

inputs:
store-file-path:
description: The path to the store file
required: true
test_path:
description: 'Path to the test file or folder'
required: false
default: '.'
test_files_pattern:
description: 'Pattern to match the test files'
required: false
default: '*.fga.yaml'

runs:
using: composite
Expand All @@ -19,4 +24,15 @@ runs:
cache: enable
- name: Run OpenFGA CLI
shell: bash
run: fga model test --tests ${{ inputs.store-file-path }}
run: |
while IFS= read -r -d '' test_file
do
((test_files_count+=1))
echo "Running FGA test file ${test_file}"
fga model test --tests "${test_file}"
done < <(find ${{ inputs.test_path }} -name "${{ inputs.test_files_pattern }}" -print0)

if [[ ${test_files_count} -eq 0 ]]; then
echo "No FGA test file found for path '${{ inputs.test_path }}' and pattern '${{ inputs.test_files_pattern }}'"
exit 1
fi
Loading