2020-02-04 13:53:45 -08:00
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import json
|
|
|
|
import jc.parsers.yaml
|
|
|
|
|
|
|
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
|
|
|
|
|
|
|
|
class MyTests(unittest.TestCase):
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
# input
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sc.yaml'), 'r', encoding='utf-8') as f:
|
2020-02-04 13:53:45 -08:00
|
|
|
self.generic_yaml_istio_sc = f.read()
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sidecar.yaml'), 'r', encoding='utf-8') as f:
|
2020-02-04 13:53:45 -08:00
|
|
|
self.generic_yaml_istio_sidecar = f.read()
|
|
|
|
|
|
|
|
# output
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sc.json'), 'r', encoding='utf-8') as f:
|
2020-02-04 13:53:45 -08:00
|
|
|
self.generic_yaml_istio_sc_json = json.loads(f.read())
|
|
|
|
|
2020-03-04 19:47:03 -08:00
|
|
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/generic/yaml-istio-sidecar.json'), 'r', encoding='utf-8') as f:
|
2020-02-04 13:53:45 -08:00
|
|
|
self.generic_yaml_istio_sidecar_json = json.loads(f.read())
|
|
|
|
|
2020-06-12 12:25:07 -07:00
|
|
|
def test_yaml_nodata(self):
|
|
|
|
"""
|
|
|
|
Test the YAML parser with no data
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.yaml.parse('', quiet=True), [])
|
|
|
|
|
2020-02-04 13:53:45 -08:00
|
|
|
def test_yaml_istio_sc(self):
|
|
|
|
"""
|
|
|
|
Test the Istio SC yaml file
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.yaml.parse(self.generic_yaml_istio_sc, quiet=True), self.generic_yaml_istio_sc_json)
|
|
|
|
|
|
|
|
def test_yaml_istio_sidecar(self):
|
|
|
|
"""
|
|
|
|
Test the Istio Sidecar yaml file
|
|
|
|
"""
|
|
|
|
self.assertEqual(jc.parsers.yaml.parse(self.generic_yaml_istio_sidecar, quiet=True), self.generic_yaml_istio_sidecar_json)
|
|
|
|
|
2022-04-19 14:43:47 -04:00
|
|
|
def test_yaml_datetime(self):
|
|
|
|
"""
|
|
|
|
Test yaml file with datetime object (should convert to a string)
|
|
|
|
"""
|
|
|
|
data = 'deploymentTime: 2022-04-18T11:12:47'
|
|
|
|
expected = [{"deploymentTime":"2022-04-18T11:12:47"}]
|
|
|
|
self.assertEqual(jc.parsers.yaml.parse(data, quiet=True), expected)
|
|
|
|
|
2020-02-04 13:53:45 -08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|