-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi-spec_validation_test.sh
55 lines (43 loc) · 2.11 KB
/
api-spec_validation_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
setUp()
{
originalPath=$PATH
PATH=$PWD:$PATH
# Setup local variables to dynamically generate the API spec URL from pull request.
githubRawResourceBaseUrl=https://raw.githubusercontent.com
githubUsername=amardeshbd
githubProjectId=medium-api-specification
openApiSpecFileName=medium-api-specification.yaml
echo "Executing tests... ^_^"
}
# Tests the swagger using online service
#
# DEV NOTE:
# ----------------
# Instead of comparing, string output, I had to calculate string size because if service
# gives error response, the unit test validation fails. See sample below
#
# Sample RESPONSE: {"schemaValidationMessages":[{"level":"error","message":"Can't read from file http://bla.bla.json"}]}
#
# shunit2:ERROR assertEquals() requires two or three arguments; 7 given
# shunit2:ERROR 1: Validation failed {} : {"schemaValidationMessages":[{"level":"error","message":"Can't 4: read
#
testOpenApiSpecValidity() {
expectedOutput="{}"
expectedOutputSize=${#expectedOutput}
specUrl="$githubRawResourceBaseUrl/$githubUsername/$githubProjectId/$BRANCH/$openApiSpecFileName"
# 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