def test_splunk_connection_docker(testdir):
    """Make sure that pytest accepts our fixture."""

    # create a temporary pytest test module
    testdir.makepyfile(test_connection_only)

    # Copy the content of source to destination

    shutil.copytree(
        os.path.join(testdir.request.fspath.dirname, "addons/TA_fiction"),
        os.path.join(testdir.tmpdir, "package"),
    )

    setup_test_dir(testdir)
    SampleGenerator.clean_samples()
    Rule.clean_rules()

    # run pytest with the following cmd args
    result = testdir.runpytest(
        "--splunk-type=docker", "-v",
    )

    # fnmatch_lines does an assertion internally
    result.assert_outcomes(passed=1, failed=0)

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0
def test_splunk_setup_fixture(testdir):
    testdir.makepyfile(
        """
        from pytest_splunk_addon.standard_lib.addon_basic import Basic
        class Test_App(Basic):
            def empty_method():
                pass

        """
    )
    setup_test_dir(testdir)
    SampleGenerator.clean_samples()
    Rule.clean_rules()
    with open(
        os.path.join(
            testdir.request.fspath.dirname,
            "enable_saved_search_conftest.py"
        )
    ) as conf_test_file:
        testdir.makeconftest(conf_test_file.read())

    shutil.copytree(
            os.path.join(testdir.request.fspath.dirname, "addons/TA_SavedSearch"),
            os.path.join(testdir.tmpdir, "package"),
        )

    result = testdir.runpytest(
        "--splunk-type=docker",  "-v", "-k saved_search_lookup","--search-interval=4","--search-retry=4", "--search-index=*,_internal",
    )

    result.assert_outcomes(
        passed=2
    )
def test_splunk_app_fiction(testdir):
    """Make sure that pytest accepts our fixture."""

    testdir.makepyfile(
        """
        from pytest_splunk_addon.standard_lib.addon_basic import Basic
        class Test_App(Basic):
            def empty_method():
                pass

    """
    )

    shutil.copytree(
        os.path.join(testdir.request.fspath.dirname, "addons/TA_fiction"),
        os.path.join(testdir.tmpdir, "package"),
    )

    setup_test_dir(testdir)
    SampleGenerator.clean_samples()
    Rule.clean_rules()

    # run pytest with the following cmd args
    result = testdir.runpytest(
        "--splunk-type=docker",  "-v", "-m splunk_searchtime_fields","--search-interval=4","--search-retry=4","--search-index=*,_internal",
    )

    result.stdout.fnmatch_lines_random(constants.TA_FICTION_PASSED)
    result.assert_outcomes(passed=len(constants.TA_FICTION_PASSED), failed=0)

    # make sure that that we get a '0' exit code for the testsuite
    assert result.ret == 0
def test_splunk_app_cim_broken(testdir):
    """Make sure that pytest accepts our fixture."""

    testdir.makepyfile(
        """
        from pytest_splunk_addon.standard_lib.addon_basic import Basic
        class Test_App(Basic):
            def empty_method():
                pass

    """
    )

    shutil.copytree(
        os.path.join(testdir.request.fspath.dirname, "addons/TA_CIM_Broken"),
        os.path.join(testdir.tmpdir, "package"),
    )

    shutil.copytree(
        os.path.join(testdir.request.fspath.dirname, "test_data_models"),
        os.path.join(testdir.tmpdir, "tests/data_models"),
    )

    setup_test_dir(testdir)
    SampleGenerator.clean_samples()
    Rule.clean_rules()

    # run pytest with the following cmd args
    result = testdir.runpytest(
        "--splunk-type=docker",
        "--splunk-dm-path=tests/data_models",
        "-v",
        "-m splunk_searchtime_cim",
        "--search-interval=4",
        "--search-retry=4",
        "--search-index=*,_internal",
    )

    # fnmatch_lines does an assertion internally
    result.stdout.fnmatch_lines_random(
        constants.TA_CIM_BROKEN_PASSED + constants.TA_CIM_BROKEN_FAILED
    )
    result.assert_outcomes(
        passed=len(constants.TA_CIM_BROKEN_PASSED),
        failed=len(constants.TA_CIM_BROKEN_FAILED),
    )

    # The test suite should fail as this is a negative test
    assert result.ret != 0
예제 #5
0
def test_splunk_app_requirements_scripted(testdir):
    """Make sure that pytest accepts our fixture."""

    testdir.makepyfile("""
        from pytest_splunk_addon.standard_lib.addon_requirements_basic import RequirementBasic
        class Test_App(RequirementBasic):
            def empty_method():
                pass
    """)

    shutil.copytree(
        os.path.join(testdir.request.fspath.dirname,
                     "addons/TA_requirement_test_uf"),
        os.path.join(testdir.tmpdir, "package"),
    )

    setup_test_dir(testdir)
    SampleGenerator.clean_samples()
    Rule.clean_rules()

    # run pytest with the following cmd args
    result = testdir.runpytest(
        "--splunk-type=docker",
        "-v",
        "-m splunk_searchtime_requirements",
        "--search-interval=4",
        "--search-retry=4",
        "--search-index=*,_internal",
        "--requirement-test=tests/requirement_test_scripted",
    )
    logger.info(result.outlines)
    logger.info(len(constants.TA_REQUIREMENTS_SCRIPTED_PASSED))
    logger.info(len(constants.TA_REQUIREMENTS_SCRIPTED_FAILED))
    result.stdout.fnmatch_lines_random(
        constants.TA_REQUIREMENTS_SCRIPTED_PASSED +
        constants.TA_REQUIREMENTS_SCRIPTED_FAILED)
    result.assert_outcomes(passed=len(
        constants.TA_REQUIREMENTS_SCRIPTED_PASSED),
                           failed=1)

    # make sure that that we get a non '0' exit code for the testsuite as it contains failure
    assert result.ret != 0