Skip to content

Commit

Permalink
feat!: support multiple test files (#8)
Browse files Browse the repository at this point in the history
* feat!: support multiple test files

* ci: run test workflow on PR
  • Loading branch information
le-yams authored Apr 4, 2024
1 parent 4f18595 commit bbdc3f5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 12 deletions.
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,38 @@
[![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
Expand All @@ -25,7 +48,25 @@ jobs:
steps:
- uses: openfga/[email protected]
with:
store-file-path: ./example/model.fga.yaml
test_path: example
```

### Running tests of a single file

```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/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

0 comments on commit bbdc3f5

Please sign in to comment.