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

Add 'validate_unversioned_path' option, which is false by default #53

Merged
merged 7 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 6 additions & 3 deletions .github/workflows/ci_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
import os


def check_output(expected_keys: list):
expected_results_keys = ["success_count", "failure_count"] # not complete list
results = json.loads(os.getenv("RESULTS"))
Expand All @@ -16,15 +17,17 @@ def check_output(expected_keys: list):


if __name__ == "__main__":
commands = ["default", "all_versioned_paths"]
commands = ["default", "all_versioned_paths", "validate_unversioned_path"]

parser = argparse.ArgumentParser()
parser.add_argument("cmd", help="Command to run.", type=str, choices=commands)
args = parser.parse_args()

if args.cmd == "default":
check_output(["unversioned", "v1"])
check_output(["v1"])
elif args.cmd == "all_versioned_paths":
check_output(["unversioned", "v1", "v1.0", "v1.0.0"])
check_output(["v1", "v1.0", "v1.0.0"])
elif args.cmd == "validate_unversioned_path":
check_output(["unversioned", "v1"])
else:
exit(f"Wrong command, it must be one of {commands}")
26 changes: 25 additions & 1 deletion .github/workflows/validator_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@ jobs:
.github/workflows/wait_for_it.sh localhost:3213 -t 120
sleep 15

- name: Run action
- name: Run action (validating the unversioned path)
uses: ./
with:
port: 3213
path: /
validate_unversioned_path: yes

- name: Run action (without validating the unversioned path)
uses: ./
with:
port: 3213
path: /
validate_unversioned_path: no

validator_index:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -67,13 +75,15 @@ jobs:
port: 3213
path: /
all versioned paths: yes
validate_unversioned_path: yes

- name: Run action (setting path to empty string)
uses: ./
with:
port: 3213
path: ""
all versioned paths: yes
validate_unversioned_path: yes

bats:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -179,3 +189,17 @@ jobs:
env:
RESULTS: "${{ steps.action_all.outputs.results }}"
run: python .github/workflows/ci_helper.py all_versioned_paths

- name: Run action with validate_unversioned_path to retrieve output
id: action_unversioned
uses: ./
with:
port: 3213
path: /
create output: true
validate_unversioned_path: true

- name: Check "validate_unversioned_path" output
env:
RESULTS: "${{ steps.action_unversioned.outputs.results }}"
run: python .github/workflows/ci_helper.py validate_unversioned_path
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Latest versions:

| Used tag | Effective version |
| :---: | :---: |
| `v2` | [`v2.2.2`](https://github.com/Materials-Consortia/optimade-validator-action/releases/tag/v2.2.2)
| `v2` | [`v2.2.0`](https://github.com/Materials-Consortia/optimade-validator-action/releases/tag/v2.2.0)
ml-evs marked this conversation as resolved.
Show resolved Hide resolved
| `v1` | [`v1.2.0`](https://github.com/Materials-Consortia/optimade-validator-action/releases/tag/v1.2.0)

## Example usage
Expand Down Expand Up @@ -57,7 +57,8 @@ This can be chosen using the input `validator_version`.

| Input | Description | Usage | Default | Action version |
| :---: | :--- | :---: | :---: | :---: |
| `all_versioned_paths` | Whether to test all possible versioned base URLs:<br><br>/vMAJOR<br>/vMAJOR.MINOR<br>/vMAJOR.MINOR.PATCH<br><br>The latter two being optional base URLs according to the specification. | Optional | `false` | `v1+`
| `all_versioned_paths` | Whether to test the optional versioned base URLs:<br><br>/vMAJOR<br>/vMAJOR.MINOR<br>/vMAJOR.MINOR.PATCH<br><br>If `false`, only the mandatory /vMAJOR URL will be tested. | Optional | `false` | `v1+`
| `validate_unversioned_path` | Whether to validate the input URL as a full OPTIMADE implementation without appending any version.<br><br>This action assumes that the 'path' parameter will contain an unversioned URL. As it is not mandatory to run a full OPTIMADE implementation from the unversioned URL, by default, this action will not perform any validation of this URL, beyond checking the `/versions` endpoint. | Optional | `false` | `v2.3+`
CasperWA marked this conversation as resolved.
Show resolved Hide resolved
| `as_type` | Validate the request URL with the provided type, rather than scanning the entire implementation.<br>Example values: `structures`, `reference`. For a full list of values see the [OPTIMADE Python tools documentation](https://www.optimade.org/optimade-python-tools/api_reference/validator/validator/#optimade.validator.validator.ImplementationValidator.__init__). | Optional | - | `v1+`
| `domain` | Domain for the OPTIMADE URL (defaults to the GitHub Actions runner host). | Optional | `gh_actions_host` | `v1+`
| `fail_fast` | Whether or not to exit and return a non-zero error code on first failure. | Optional | `false` | `v2+`
Expand Down
16 changes: 13 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ inputs:

all versioned paths:
description: >
Whether to test all possible versioned base URLs:
/vMAJOR; /vMAJOR.MINOR; /vMAJOR.MINOR.PATCH
The latter two being optional base URLs according to the specification.
Whether to test the optional versioned URLs:
/vMAJOR.MINOR; /vMAJOR.MINOR.PATCH
If `false`, only the mandatory /vMAJOR URL will be tested.
required: false
default: false

validate unversioned paths:
description: >
Whether to validate the input URL as a full OPTIMADE implementation without appending any version.
This action assumes that the `path` parameter will contain an unversioned URL.
As it is not mandatory to run a full OPTIMADE implementation from the unversioned URL,
by default, this action will not perform any validation of this URL, beyond checking
the `/versions` endpoint.
required: false
default: false

as type:
description: >
Validate the request URL with the provided type, rather than scanning the entire implementation.
Expand Down
13 changes: 11 additions & 2 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,17 @@ esac

# Run validator for unversioned base URL
# Echo line is for testing
echo "run_validator: ${run_validator}${INPUT_PATH}${index}" > ./.entrypoint-run_validator.txt
sh -c "${run_validator}${INPUT_PATH}${index}" | tee "unversioned.json"
case ${INPUT_VALIDATE_UNVERSIONED_PATH} in
y | Y | yes | Yes | YES | true | True | TRUE | on | On | ON)
echo "run_validator: ${run_validator}${INPUT_PATH}${index}" > ./.entrypoint-run_validator.txt
sh -c "${run_validator}${INPUT_PATH}${index}" | tee "unversioned.json"
;;
n | N | no | No | NO | false | False | FALSE | off | Off | OFF)
;;
*)
echo "Non-valid input for 'validate unversioned path': ${INPUT_VALIDATE_UNVERSIONED_PATH}. Will use default (false)."
;;
esac

# Run validator for versioned base URL(s)
if [ "${INPUT_PATH}" = "/" ]; then
Expand Down
23 changes: 17 additions & 6 deletions tests/test_all_versioned_paths.bats
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,26 @@ load 'test_fixtures'
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "all_versioned_paths=True" {
export INPUT_ALL_VERSIONED_PATHS=True
run ${ENTRYPOINT_SH}
refute_output --partial "ERROR"

OPTIMADE_VERSION=("v1.0" "v1.0.0")
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[0]}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[1]}"
}

@test "all_versioned_paths=True & validate_unversioned_path=True" {
export INPUT_ALL_VERSIONED_PATHS=True INPUT_VALIDATE_UNVERSIONED_PATH=True
run ${ENTRYPOINT_SH}
refute_output --partial "ERROR"

OPTIMADE_VERSION=("v1.0" "v1.0.0")
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
Expand All @@ -25,15 +36,16 @@ run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[0]}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[1]}"
}


@test "all_versioned_paths=invalid_value" {
# For an invalid value, it should fallback to the default (false)
export INPUT_ALL_VERSIONED_PATHS=invalid_value
run ${ENTRYPOINT_SH}
refute_output --partial "ERROR"
assert_output --partial "Non-valid input for 'all versioned paths': ${INPUT_ALL_VERSIONED_PATHS}. Will use default (false)."

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "all_versioned_paths=True for old spec v0.10.1" {
Expand All @@ -53,8 +65,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"

OPTIMADE_VERSION=("v0" "v0.10" "v0.10.1")
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[0]}
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[0]}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[1]}
run_validator: ${TEST_BASE_RUN_VALIDATOR}${OPTIMADE_VERSION[2]}"
}
9 changes: 3 additions & 6 deletions tests/test_as_type.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ load 'test_fixtures'
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "as_type='structure'" {
Expand All @@ -22,8 +21,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"

TEST_BASE_RUN_VALIDATOR="optimade-validator $( for i in {1..${INPUT_VERBOSITY}}; do echo '-v '; done; )--as-type ${VALID_AS_TYPE_VALUE} ${INPUT_PROTOCOL}://${INPUT_DOMAIN}${INPUT_PATH}"
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
}

@test "as_type='non_valid_input' (invalid value, should fail with status 1 and message)" {
Expand All @@ -37,6 +35,5 @@ run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"

TEST_BASE_RUN_VALIDATOR="optimade-validator $( for i in {1..${INPUT_VERBOSITY}}; do echo '-v '; done; )--as-type ${INVALID_AS_TYPE_VALUE} ${INPUT_PROTOCOL}://${INPUT_DOMAIN}${INPUT_PATH}"
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
}
9 changes: 3 additions & 6 deletions tests/test_create_output.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ load 'test_fixtures'

TEST_BASE_RUN_VALIDATOR="optimade-validator --json ${INPUT_PROTOCOL}://${INPUT_DOMAIN}${INPUT_PATH}"
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
}

@test "create_output='test' (invalid value, should use default instead)" {
Expand All @@ -25,8 +24,7 @@ run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
refute_output --partial "Non-valid input for 'verbosity'"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "create_output=True (with validator_version that hasn't got the '--json' option)" {
Expand All @@ -41,6 +39,5 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
refute_output --partial "Non-valid input for 'verbosity'"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}
34 changes: 34 additions & 0 deletions tests/test_unversioned_path.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bats

load 'test_fixtures'

@test "validate_unversioned_path=False" {
export INPUT_VALIDATE_UNVERSIONED_PATH=False
run ${ENTRYPOINT_SH}
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validate_unversioned_path=True" {
export INPUT_VALIDATE_UNVERSIONED_PATH=True
run ${ENTRYPOINT_SH}
refute_output --partial "ERROR"

OPTIMADE_VERSION=("v1.0" "v1.0.0")
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validate_unversioned_path=invalid_value" {
ml-evs marked this conversation as resolved.
Show resolved Hide resolved
# For an invalid value, it should fallback to the default (false)
export INPUT_VALIDATE_UNVERSIONED_PATH=invalid_value
run ${ENTRYPOINT_SH}
assert_output --partial "Non-valid input for 'validate unversioned path': ${INPUT_VALIDATE_UNVERSIONED_PATH}. Will use default (false)."
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}
12 changes: 4 additions & 8 deletions tests/test_validator_version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ load 'test_fixtures'
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validator_version='0.10.0'" {
Expand All @@ -20,8 +19,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validator_version='v0.10.0'" {
Expand All @@ -32,8 +30,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validator_version='master'" {
Expand All @@ -43,8 +40,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
refute_output --partial "ERROR"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "validator_version='0.0.0' (invalid value, should fail with status 1 and message)" {
Expand Down
12 changes: 4 additions & 8 deletions tests/test_verbosity.bats
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ load 'test_fixtures'
refute_output --partial "Non-valid input for 'verbosity'"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "verbosity=0" {
Expand All @@ -24,8 +23,7 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"

TEST_BASE_RUN_VALIDATOR="optimade-validator ${INPUT_PROTOCOL}://${INPUT_DOMAIN}${INPUT_PATH}"
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
}

@test "verbosity='test' (invalid value, should use default instead)" {
Expand All @@ -37,8 +35,7 @@ run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output --partial "Using verbosity level: ${VERBOSITY_DEFAULT}"

run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
assert_output "run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"
}

@test "verbosity=3" {
Expand All @@ -51,6 +48,5 @@ run_validator: ${TEST_MAJOR_RUN_VALIDATOR}"

TEST_BASE_RUN_VALIDATOR="optimade-validator -v -v -v ${INPUT_PROTOCOL}://${INPUT_DOMAIN}${INPUT_PATH}"
run cat ${DOCKER_BATS_WORKDIR}/.entrypoint-run_validator.txt
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}
run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
assert_output "run_validator: ${TEST_BASE_RUN_VALIDATOR}v1"
}