# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.

import itertools
import os
import unittest

from paths.tree_walker import walk


class TestTreeWalker(unittest.TestCase):
    def setUp(self):
        self.maxDiff = None
        self.data_path = os.path.realpath(
            os.path.join(os.path.dirname(__file__), "data")
        )

    def test_walk(self):
        paths = sorted(
            list(itertools.chain(walk(self.data_path))), key=lambda path: path[0]
        )
        self.assertTrue(len(paths), 7)
        self.assertEqual(
            paths[0][1], "git/component-with-scripts-folder/scripts/build.sh"
        )
        self.assertEqual(
            paths[0][0],
            os.path.realpath(
                os.path.join(
                    self.data_path, "git/component-with-scripts-folder/scripts/build.sh"
                )
            ),
        )
