Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/firecracker
Path: blob/main/tests/integration_tests/style/test_swagger.py
1958 views
1
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
# SPDX-License-Identifier: Apache-2.0
3
"""Tests ensuring codebase style compliance for the OpenAPI specification."""
4
5
import os
6
import yaml
7
import framework.utils as utils
8
9
10
def check_yaml_style(yaml_spec):
11
"""Check if the swagger definition is correctly formatted."""
12
with open(yaml_spec, 'r') as file_stream:
13
try:
14
yaml.safe_load(file_stream)
15
# pylint: disable=broad-except
16
except Exception as exception:
17
print(str(exception))
18
19
20
def validate_swagger(swagger_spec):
21
"""Fail if OpenApi spec is not followed."""
22
validate_cmd = 'swagger-cli validate {}'.format(swagger_spec)
23
retcode, stdout, _ = utils.run_cmd(validate_cmd)
24
25
# Verify validity.
26
assert "is valid" in stdout
27
assert retcode == 0
28
29
30
def test_firecracker_swagger():
31
"""Fail if Firecracker swagger specification is malformed."""
32
swagger_spec = os.path.normpath(
33
os.path.join(os.getcwd(), '../src/api_server/swagger/firecracker.yaml')
34
)
35
check_yaml_style(swagger_spec)
36
validate_swagger(swagger_spec)
37
38