Skip to content

Commit

Permalink
Add 'validate_unversioned_path' option, which is false by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Jan 7, 2021
1 parent e00d9dc commit a74cd0a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 6 deletions.
12 changes: 11 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: yes

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
12 changes: 9 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@ 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 base URL as a full OPTIMADE implementation.
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 "Invalid 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
36 changes: 36 additions & 0 deletions tests/test_unversioned_path.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/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_BASE_RUN_VALIDATOR}
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_BASE_RUN_VALIDATOR}
run_validator: ${TEST_MAJOR_RUN_VALIDATOR}
}
@test "validate_unversioned_path=invalid_value" {
# For an invalid value, it should fallback to the default (false)
export INPUT_VALIDATE_UNVERSIONED_PATH=invalid_value
run ${ENTRYPOINT_SH}
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}"
}

0 comments on commit a74cd0a

Please sign in to comment.