Last active
August 21, 2016 14:31
-
-
Save hossain-khan/6ba8116710c789b68608e9cf232e82e7 to your computer and use it in GitHub Desktop.
Shell script that uses shUnit2 for validating OpenAPI specification file. This file is taken from https://github.com/amardeshbd/medium-api-specification and **modified** for embedding on web, see github project for details.
This file contains hidden or 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
#!/bin/sh | |
# NOTE: This file is modified version taken from: | |
# https://github.com/amardeshbd/medium-api-specification/blob/master/api-spec_validation_test.sh | |
# Tests the swagger specificaton using online service | |
testOpenApiSpecValidity() { | |
expectedOutput="{}" | |
expectedOutputSize=${#expectedOutput} | |
# Prepares the spec URL from GitHub Pull-Request (PR) | |
specUrl="https://raw.githubusercontent.com/amardeshbd/medium-api-specification/$BRANCH/medium-api-specification.yaml" | |
# Now prepare the open API spec file to use the online validator service. | |
validationUrl="http://online.swagger.io/validator/debug?url=$specUrl" | |
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" | |
echo "Validating ENV Variables: TRAVIS_BRANCH=$TRAVIS_BRANCH, PR=$PR, BRANCH=$BRANCH" | |
echo "OpenAPI Specification File=$validationUrl" | |
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" | |
validationOutput=$(curl $validationUrl) | |
validationOutputSize=${#validationOutput} | |
echo "Testing swagger validation - current output is: $validationOutput" | |
echo "Expected valid size: $expectedOutputSize, current output: $validationOutputSize" | |
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" | |
assertEquals "Validation failed - service unavailable or error found." $expectedOutputSize $validationOutputSize | |
} | |
# Execute shunit2 to run the tests (downloaded via `.travis.yaml`) | |
. shunit2-2.1.6/src/shunit2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment