Example #1
0
    def test_string_replacements(self):
        """Mimic the string replacement used for env var interpolation in charts"""
        # Load a new yaml file with an "env var" of replacethis: ""
        yaml_file = self.yaml_data.getvalue(
        ) + '\nexpect_string: "${REPLACEME}"\nexpect_bool: ${REPLACEME}\n'

        # Serialize the yaml into memory
        initial_read = Handler.load(StringIO(yaml_file))

        # Redump the yaml (mimicing the temp file yaml for helm)
        initial_dump = Handler.dump(initial_read)

        # Do a string replacement on the env var in the new dump
        yaml_file = Template(initial_dump).substitute({'REPLACEME': 'true'})

        # Re-read the replaced string
        data = Handler.load(StringIO(yaml_file))

        # Test that type is consistent
        self.assertIsInstance(
            data["expect_bool"], bool,
            "Expected 'expect_bool' to be a bool due to no quotes in the initial yaml."
        )
        self.assertIsInstance(
            data["expect_string"], str,
            "Expected 'expect_string' to remain a string because it was quoted in the initial yaml."
        )
Example #2
0
    def test_load_to_dump_to_load(self):
        """Assert when we load data and then dump and then reload it's equal"""
        data = Handler.load(self.yaml_data)
        yaml = StringIO(Handler.dump(data))
        final_data = Handler.load(yaml)

        self.assertDictEqual(data, final_data)
Example #3
0
 def test_diff_types(self):
     self.service_manifest.diff(Manifest(yaml_handler.load(self.document)),
                                difftype='unified')
     self.service_manifest.diff(Manifest(yaml_handler.load(self.document)),
                                difftype='context')
     with self.assertRaises((TypeError)):
         self.service_manifest.diff(Manifest(
             yaml_handler.load(self.document)),
                                    difftype='wrong')
Example #4
0
    def test_yaml_loaded_integration(self, chartConfigMock):
        yaml_file = StringIO('''
---
charts:
  my-chart:
    set-values:
      keyone: value one
      keytwo:
        keythree: value three
        keyfour:
        - --settings
      keyfive:
      - --one
      - --two
      deeplynested_objects:
      - name: hiya
        another:
          nested: value
          nesting: value
      - non: conforming
        lists:
        - more lists
        - and more
        - and:
            a_random_dict: value
''')
        course = Handler.load(yaml_file)
        chart = Chart(course["charts"], None)

        chartConfig = chartConfigMock()
        chartConfig.course_base_directory = '.'
        chartConfig.dryrun = False

        chart.build_set_arguments()
        self.assertEqual(chart.args, [
            "--set",
            "keyone=value one",
            "--set",
            "keytwo.keythree=value three",
            "--set",
            "keytwo.keyfour[0]=--settings",
            "--set",
            "keyfive[0]=--one",
            "--set",
            "keyfive[1]=--two",
            "--set",
            "deeplynested_objects[0].name=hiya",
            "--set",
            "deeplynested_objects[0].another.nested=value",
            "--set",
            "deeplynested_objects[0].another.nesting=value",
            "--set",
            "deeplynested_objects[1].non=conforming",
            "--set",
            "deeplynested_objects[1].lists[0]=more lists",
            "--set",
            "deeplynested_objects[1].lists[1]=and more",
            "--set",
            "deeplynested_objects[1].lists[2].and.a_random_dict=value",
        ])
Example #5
0
    def test_dump(self):
        """Assert that dump returns a string that is valid yaml"""
        # Read the dict into a yaml file string via stringIO
        yaml_file = StringIO(Handler.dump(self.example_dict))
        # Read the stringio "file" into a dict again
        data = Handler.load(yaml_file)

        # Assert that the data that was dumped and loaded is completely equal
        self.assertDictEqual(data, self.example_dict)
Example #6
0
def lint_course_file(course_file: BufferedReader):
    v = Validator()
    course_file_object = Handler.load(course_file)
    v.check(course_file_object)
    if len(v.errors) > 0:
        logging.error("Schema Validation Errors:")
        for err in v.raw_errors:
            logging.error("{}".format(err))
        raise SchemaValidationError(
            "Course file has schema validation errors.")
Example #7
0
def validate_course_file(course_file: BufferedReader):
    v = Validator()
    course_file_object = Handler.load(course_file)
    v.check(course_file_object)
    if len(v.errors) > 0:
        logging.debug("Schema Validation Errors:")
        for err in v.raw_errors:
            logging.debug("{}".format(err))
        raise SchemaValidationError(
            "Course file has schema validation errors. "
            "Please see the docs on schema validation or --log-level debug for in depth validation output.\n\n{}.".format('\n'.join(v.errors))
        )
Example #8
0
    def test_find_congruent_manifest(self):
        with open('./reckoner/tests/files/service.yaml') as f:
            document = f.read()
        service_manifest = Manifest(yaml_handler.load(document))

        print(service_manifest.kind)

        found = self.manifests.find_congruent_manifest(service_manifest)
        print(found)
        self.assertIsInstance(found, (Manifest))
        self.assertEqual(found.kind, 'Service')
        self.assertEqual(found.name, 'reckoner-test-service')
        self.assertEqual(found.annotations, {})
Example #9
0
 def test_str_method(self):
     self.assertEqual(yaml_handler.load(str(self.service_manifest)),
                      yaml_handler.load(self.document))
Example #10
0
 def setUp(self):
     with open('./reckoner/tests/files/service.yaml') as f:
         self.document = f.read()
     self.service_manifest = Manifest(yaml_handler.load(self.document))
Example #11
0
 def test_load_duplicate_keys(self):
     """Assert that the initial key defined, of duplicate keys, takes precedence"""
     with_duplicate = StringIO("{}\nbool: false\n".format(
         self.yaml_data.getvalue()))
     yaml = Handler.load(with_duplicate)
     self.assertEqual(yaml["bool"], True)
Example #12
0
 def test_load_errors(self):
     """Assert that load fails on invalid yaml"""
     with self.assertRaises(Exception):
         Handler.load(self.bad_yaml_data)
Example #13
0
 def test_load(self):
     """Assert that load can load valid yaml"""
     yaml = Handler.load(self.yaml_data)
     self.assertEqual(yaml["my_key"], "some_val")
     self.assertEqual(yaml["bool"], True)