Exemplo n.º 1
0
class TestKubeconfigValidator(unittest.TestCase):
    def setUp(self):
        self._validator = KubeconfigValidator()

    def test_valid(self):
        valid_cases = glob.glob(get_testdata( "valid_*" ))
        for case in valid_cases:
            with open(case, 'r') as stream:
                content_dict = ordered_yaml_load(stream)
            if content_dict is not None:
                config = Kubeconfig(None, content_dict)
                try:
                    self._validator.validate_config(config)
                except KubeconfigError as e:
                    self.fail("Valid file {0} raised {1}.".format(case, e))

    def test_invalid(self):
        invalid_cases = glob.glob(get_testdata("invalid_*"))
        for case in invalid_cases:
            with open(case, 'r') as stream:
                content_dict = ordered_yaml_load(stream)
            config = Kubeconfig(None, content_dict)
            self.assertRaises(KubeconfigCorruptedError,
                              self._validator.validate_config, 
                              config)
Exemplo n.º 2
0
class TestKubeconfigValidator(unittest.TestCase):
    def setUp(self):
        self._validator = KubeconfigValidator()

    def test_valid(self):
        valid_cases = glob.glob(get_testdata( "valid_*" ))
        for case in valid_cases:
            with open(case, 'r') as stream:
                content_dict = ordered_yaml_load(stream)
            if content_dict is not None:
                config = Kubeconfig(None, content_dict)
                try:
                    self._validator.validate_config(config)
                except KubeconfigError as e:
                    self.fail("Valid file {0} raised {1}.".format(case, e))
Exemplo n.º 3
0
    def __init__(self, env_variable, path_in, validator=None, loader=None):
        """
        Parse KUBECONFIG into a list of absolute paths.
        Also replace the empty list with DEFAULT_PATH

        :param env_variable: KUBECONFIG as a long string
        :type env_variable: string

        :param path_in: The path passed in through the CLI
        :type path_in: string or None
        """
        if validator is None:
            validator = KubeconfigValidator()
        self._validator = validator

        if loader is None:
            loader = KubeconfigLoader(validator)
        self._loader = loader

        if path_in is not None:
            # Override environment variable
            self._paths = [self._expand_path(path_in)]
        else:
            # Get the list of paths from the environment variable
            if env_variable == "":
                env_variable = DEFAULT_PATH
            self._paths = [
                self._expand_path(element)
                for element in env_variable.split(os.pathsep)
                if len(element.strip()) > 0
            ]
            if len(self._paths) == 0:
                self._paths = [DEFAULT_PATH]
Exemplo n.º 4
0
 def setUp(self):
     self._validator = KubeconfigValidator()
Exemplo n.º 5
0
 def setUp(self):
     self._validator = KubeconfigValidator()