示例#1
0
"""Unit tests for the rules module. Run using nosetests."""

import os
import unittest

from dateutil import parser as date_parser
from nose.tools import nottest

import libanalysis.rules as rules
import libanalysis.readers as readers
import libanalysis.util as util

from test_lib.fixture_files import FixtureFiles

FIXTURE_FILES = FixtureFiles(os.path.join(os.path.dirname(__file__)), 'analysis')


class TestResourceRules(unittest.TestCase):
    """Test class evaluates correctness of resource sanity check rules.
    """
    def setUp(self):
        """Specifies the paths used to fetch JSON testing files. Additionally,
        sets up the common parameters for each operation being tested.
        """
        # parameters used in test cases
        self.path_ftdc_3node_repl = FIXTURE_FILES.fixture_file_path(
            'linux_3node_replSet_p1.ftdc.metrics')
        self.single_chunk_3node = self._first_chunk(self.path_ftdc_3node_repl)
        self.times_3node = self.single_chunk_3node[rules.FTDC_KEYS['time']]
        self.members_3node = ['0', '1', '2']
import shutil
import unittest

from mock import patch, call, mock_open, MagicMock, ANY
from testfixtures import LogCapture, log_capture

from common.config import ConfigDict
import common.utils
import infrastructure_provisioning as ip
import test_config
from test_lib.fixture_files import FixtureFiles
import test_lib.structlog_for_test as structlog_for_test

#pylint: disable=too-many-locals

FIXTURE_FILES = FixtureFiles(os.path.dirname(__file__))

# If VERSION is updated then the following files also need to be modified
# bin/tests/unittest-files/terraform/provisioned.initialsync-logkeeper
# bin/tests/unittest-files/terraform/provisioned.replica
# bin/tests/unittest-files/terraform/provisioned.shard


class TestInfrastructureProvisioning(unittest.TestCase):
    """
    Test suite for infrastructure_provisioning.py
    """
    def setUp(self):
        self.os_environ_patcher = patch('infrastructure_provisioning.os.environ')
        self.mock_environ = self.os_environ_patcher.start()
        self.dsi_path = os.path.dirname(
示例#3
0
"""Unit tests for `log_analysis.py`."""

import unittest
from os import path

from dsi.libanalysis import log_analysis
from test_lib.fixture_files import FixtureFiles

FIXTURE_FILES = FixtureFiles()


class TestLogAnalysis(unittest.TestCase):
    """Test suite."""
    def test_get_log_file_paths(self):
        """Test `_get_bad_log_lines()`."""

        log_dir = FIXTURE_FILES.fixture_file_path("analysis",
                                                  "test_log_analysis")
        expected_paths = set([
            path.join(log_dir, "log_subdir1/mongod.log"),
            path.join(log_dir, "log_subdir2/log_subsubdir/mongod.log"),
        ])
        actual_paths = set(log_analysis._get_log_file_paths(log_dir))
        self.assertEqual(expected_paths, actual_paths)
示例#4
0
''' Test config_test_control.py '''

import logging
import os
import unittest

from mock import Mock, patch
from testfixtures import LogCapture

import test_control
from common.config import ConfigDict
from common.remote_host import RemoteHost
from test_lib.fixture_files import FixtureFiles

FIXTURE_FILES = FixtureFiles(dir_name=os.path.dirname(__file__),
                             subdir_name='config_test_control')


class TestConfigTestControl(unittest.TestCase):
    ''' Test config_test_control.py'''
    def setUp(self):
        """
        Setup basic environment
        """
        # Mocking `ConfigDict.assert_valid_ids` because it enforces structural constraints on yaml
        # files that aren't necessary here.
        with patch('common.config.ConfigDict.assert_valid_ids'
                   ) as mock_assert_valid_ids:
            prev_dir = os.getcwd()
            os.chdir(FIXTURE_FILES.fixture_dir_path)
            self.config = ConfigDict('test_control')
示例#5
0
Most of the functionality of multi_patch_builds.py would require an evergreen client in PATH,
and also a checked out mongo git repo, and we don't want to create such complex infrastructure.
But some superficial unit testing is still possible and meaningful to execute.
"""


import os
import unittest

import yaml

from dsi.multi_patch_builds import MultiEvergreen
from test_lib.fixture_files import FixtureFiles
from test_lib.test_requests_parent import TestRequestsParent

FIXTURE = FixtureFiles()


class TestMultiEvergreen(TestRequestsParent):
    """
    Test the MultiEvergreen client class.
    """

    @classmethod
    def tearDownClass(cls):
        """Remove test output file"""
        os.remove("5873a2613ff1224e8e0003ea.yml")

    def test_parse_options(self):
        """MultiEvergreen: parse options."""
        expected = {
示例#6
0
        :return: a dict with keys being the basenames and values being the loaded yaml contents
        """
        out = {}
        for basename in os.listdir(dirname):
            with open(os.path.join(dirname, basename)) as yaml_file:
                out[basename] = yaml.safe_load(yaml_file)
        return out

    def expect_actual(self) -> (dict, dict):
        self._write()
        expected = FixtureTestCase.load_dir(self.expected_dir)
        actual = FixtureTestCase.load_dir(self.actual_dir)
        return expected, actual


FIXTURE_FILES = FixtureFiles()
EXPANSIONS_DIR = FIXTURE_FILES.fixture_file_path("expansions")


class TestWriteExpansions(unittest.TestCase):
    def setUp(self):
        self.into_dir_base = tempfile.mkdtemp()

    def tearDown(self) -> None:
        shutil.rmtree(self.into_dir_base)

    def test_missing_data(self):
        input_file = FIXTURE_FILES.fixture_file_path("expansions",
                                                     "patch-dsi-selftest",
                                                     "expansions.yml")
        with open(input_file) as yaml_file: