diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:54:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-07-24 09:54:44 +0000 |
commit | 836b47cb7e99a977c5a23b059ca1d0b5065d310e (patch) | |
tree | 1604da8f482d02effa033c94a84be42bc0c848c3 /fluent-bit/tests/lib/shunit2/examples | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.tar.xz netdata-836b47cb7e99a977c5a23b059ca1d0b5065d310e.zip |
Merging upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/tests/lib/shunit2/examples')
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/equality_test.sh | 9 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/lineno_test.sh | 15 | ||||
-rw-r--r-- | fluent-bit/tests/lib/shunit2/examples/math.inc | 17 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/math_test.sh | 25 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/mkdir_test.sh | 79 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/mock_file.sh | 80 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/mock_file_test.sh | 33 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/party_test.sh | 16 | ||||
-rwxr-xr-x | fluent-bit/tests/lib/shunit2/examples/suite_test.sh | 32 |
9 files changed, 0 insertions, 306 deletions
diff --git a/fluent-bit/tests/lib/shunit2/examples/equality_test.sh b/fluent-bit/tests/lib/shunit2/examples/equality_test.sh deleted file mode 100755 index 7b5664033..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/equality_test.sh +++ /dev/null @@ -1,9 +0,0 @@ -#! /bin/sh -# file: examples/equality_test.sh - -testEquality() { - assertEquals 1 1 -} - -# Load and run shUnit2. -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/lineno_test.sh b/fluent-bit/tests/lib/shunit2/examples/lineno_test.sh deleted file mode 100755 index 11ddfc8a0..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/lineno_test.sh +++ /dev/null @@ -1,15 +0,0 @@ -#! /bin/sh -# file: examples/lineno_test.sh - -testLineNo() { - # This assert will have line numbers included (e.g. "ASSERT:[123] ...") if - # they are supported. - echo "_ASSERT_EQUALS_ macro value: ${_ASSERT_EQUALS_}" - ${_ASSERT_EQUALS_} '"not equal"' 1 2 - - # This assert will not have line numbers included (e.g. "ASSERT: ..."). - assertEquals 'not equal' 1 2 -} - -# Load and run shUnit2. -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/math.inc b/fluent-bit/tests/lib/shunit2/examples/math.inc deleted file mode 100644 index 409710669..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/math.inc +++ /dev/null @@ -1,17 +0,0 @@ -# available as examples/math.inc - -add_generic() -{ - num_a=$1 - num_b=$2 - - expr $1 + $2 -} - -add_bash() -{ - num_a=$1 - num_b=$2 - - echo $(($1 + $2)) -} diff --git a/fluent-bit/tests/lib/shunit2/examples/math_test.sh b/fluent-bit/tests/lib/shunit2/examples/math_test.sh deleted file mode 100755 index c6d00299d..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/math_test.sh +++ /dev/null @@ -1,25 +0,0 @@ -#! /bin/sh -# file: examples/math_test.sh - -testAdding() { - result=`add_generic 1 2` - assertEquals \ - "the result of '${result}' was wrong" \ - 3 "${result}" - - # Disable non-generic tests. - [ -z "${BASH_VERSION:-}" ] && startSkipping - - result=`add_bash 1 2` - assertEquals \ - "the result of '${result}' was wrong" \ - 3 "${result}" -} - -oneTimeSetUp() { - # Load include to test. - . ./math.inc -} - -# Load and run shUnit2. -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/mkdir_test.sh b/fluent-bit/tests/lib/shunit2/examples/mkdir_test.sh deleted file mode 100755 index a608e3aa3..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/mkdir_test.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh -# vim:et:ft=sh:sts=2:sw=2 -# -# Copyright 2008-2019 Kate Ward. All Rights Reserved. -# Released under the Apache 2.0 license. -# http://www.apache.org/licenses/LICENSE-2.0 -# -# shUnit2 -- Unit testing framework for Unix shell scripts. -# https://github.com/kward/shunit2 -# -# Author: kate.ward@forestent.com (Kate Ward) -# -# Example unit test for the mkdir command. -# -# There are times when an existing shell script needs to be tested. In this -# example, we will test several aspects of the the mkdir command, but the -# techniques could be used for any existing shell script. - -testMissingDirectoryCreation() { - ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} - rtrn=$? - th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" - - assertTrue 'directory missing' "[ -d '${testDir}' ]" -} - -testExistingDirectoryCreationFails() { - # Create a directory to test against. - ${mkdirCmd} "${testDir}" - - # Test for expected failure while trying to create directory that exists. - ${mkdirCmd} "${testDir}" >${stdoutF} 2>${stderrF} - rtrn=$? - assertFalse 'expecting return code of 1 (false)' ${rtrn} - assertNull 'unexpected output to stdout' "`cat ${stdoutF}`" - assertNotNull 'expected error message to stderr' "`cat ${stderrF}`" - - assertTrue 'directory missing' "[ -d '${testDir}' ]" -} - -testRecursiveDirectoryCreation() { - testDir2="${testDir}/test2" - - ${mkdirCmd} -p "${testDir2}" >${stdoutF} 2>${stderrF} - rtrn=$? - th_assertTrueWithNoOutput ${rtrn} "${stdoutF}" "${stderrF}" - - assertTrue 'first directory missing' "[ -d '${testDir}' ]" - assertTrue 'second directory missing' "[ -d '${testDir2}' ]" -} - -th_assertTrueWithNoOutput() { - th_return_=$1 - th_stdout_=$2 - th_stderr_=$3 - - assertFalse 'unexpected output to STDOUT' "[ -s '${th_stdout_}' ]" - assertFalse 'unexpected output to STDERR' "[ -s '${th_stderr_}' ]" - - unset th_return_ th_stdout_ th_stderr_ -} - -oneTimeSetUp() { - outputDir="${SHUNIT_TMPDIR}/output" - mkdir "${outputDir}" - stdoutF="${outputDir}/stdout" - stderrF="${outputDir}/stderr" - - mkdirCmd='mkdir' # save command name in variable to make future changes easy - testDir="${SHUNIT_TMPDIR}/some_test_dir" -} - -tearDown() { - rm -fr "${testDir}" -} - -# Load and run shUnit2. -[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/mock_file.sh b/fluent-bit/tests/lib/shunit2/examples/mock_file.sh deleted file mode 100755 index 812e44886..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/mock_file.sh +++ /dev/null @@ -1,80 +0,0 @@ -#!/bin/sh -# -# shUnit2 example for mocking files. -# -# This example demonstrates two different mechanisms for mocking files on the -# system. The first method is preferred for testing specific aspects of a file, -# and the second method is preferred when multiple tests need access to the -# same mock data. -# -# When mocking files, the key thing of importance is providing the code under -# test with the correct file to read. The best practice for writing code where -# files need to be mocked is either: -# - Pass the filename to be tested into a function and test that function, or -# - Provide a function that returns the name of the filename to be read. -# -# The first case is preferred whenever possible as it allows the unit test to -# be explicit about what is being tested. The second case is useful when the -# first case is not achievable. -# -# For the second case, there are two common methods to mock the filename -# returned by the function: -# - Provide a special value (e.g. a mock variable) that is only available -# during testing, or -# - Override something (e.g. the constant) in the test script. -# -# The first case is preferred as it doesn't require the unit test to alter code -# in any way. Yes, it means that the code itself knows that it is under test, -# and it behaves slightly differently than under normal conditions, but a -# visual inspection of the code by the developer should be sufficient to -# validate proper functionality of such a simple function. - -# Treat unset variables as an error. -set -u - -PASSWD='/etc/passwd' - -# Read the root UID from the passwd filename provided as the first argument. -root_uid_from_passed_filename() { - filename=$1 - root_uid "${filename}" - unset filename -} - - -# Read the root UID from the passwd filename derived by call to the -# passwd_filename() function. -root_uid_from_derived_filename() { - root_uid "$(passwd_filename)" -} - -passwd_filename() { - if [ -n "${MOCK_PASSWD:-}" ]; then - echo "${MOCK_PASSWD}" # Mock file for testing. - return - fi - echo "${PASSWD}" -} - - -# Extract the root UID. -root_uid() { awk -F: 'u==$1{print $3}' u=root "$1"; } - - -main() { - echo "root_uid_from_passed_filename:" - root_uid_from_passed_filename "${PASSWD}" - - echo - - echo "root_uid_from_derived_filename:" - root_uid_from_derived_filename -} - - -# Execute main() if this is run in standalone mode (i.e. not in a unit test). -ARGV0="$(basename "$0")" -argv0="$(echo "${ARGV0}" |sed 's/_test$//;s/_test\.sh$//')" -if [ "${ARGV0}" = "${argv0}" ]; then - main "$@" -fi diff --git a/fluent-bit/tests/lib/shunit2/examples/mock_file_test.sh b/fluent-bit/tests/lib/shunit2/examples/mock_file_test.sh deleted file mode 100755 index 1da8dd2a3..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/mock_file_test.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh -# -# shUnit2 example for mocking files. - -MOCK_PASSWD='' # This will be overridden in oneTimeSetUp(). - -test_root_uid_from_passed_filename() { - result="$(root_uid_from_passed_filename "${MOCK_PASSWD}")" - assertEquals 'unexpected root uid' '0' "${result}" -} - -test_root_uid_from_derived_filename() { - result="$(root_uid_from_derived_filename)" - assertEquals 'unexpected root uid' '0' "${result}" -} - -oneTimeSetUp() { - # Provide a mock passwd file for testing. This will be cleaned up - # automatically by shUnit2. - MOCK_PASSWD="${SHUNIT_TMPDIR}/passwd" - cat <<EOF >"${MOCK_PASSWD}" -nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false -root:*:0:0:System Administrator:/var/root:/bin/sh -daemon:*:1:1:System Services:/var/root:/usr/bin/false -EOF - - # Load script under test. - . './mock_file.sh' -} - -# Load and run shUnit2. -[ -n "${ZSH_VERSION:-}" ] && SHUNIT_PARENT=$0 -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/party_test.sh b/fluent-bit/tests/lib/shunit2/examples/party_test.sh deleted file mode 100755 index 41bd124f2..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/party_test.sh +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/sh -# file: examples/party_test.sh -# -# This test is mostly for fun. Technically, it is a bad example of a unit test -# because of the temporal requirement, namely that the year be 1999. A better -# test would have been to pass in both a known-bad and known-good year into a -# function, and test for the expected result. - -testPartyLikeItIs1999() { - year=`date '+%Y'` - assertEquals "It's not 1999 :-(" \ - '1999' "${year}" -} - -# Load and run shUnit2. -. ../shunit2 diff --git a/fluent-bit/tests/lib/shunit2/examples/suite_test.sh b/fluent-bit/tests/lib/shunit2/examples/suite_test.sh deleted file mode 100755 index 278c3a01c..000000000 --- a/fluent-bit/tests/lib/shunit2/examples/suite_test.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# file: examples/suite_test.sh -# -# This test demonstrates the use of suites. Note: the suite functionality is -# deprecated as of v2.1.0, and will be removed in a future major release. - -# suite is a special function called by shUnit2 to setup a suite of tests. It -# enables a developer to call a set of functions that contain tests without -# needing to rename the functions to start with "test". -# -# Tests that are to be called from within `suite()` are added to the list of -# executable tests by means of the `suite_addTest()` function. -suite() { - # Add the suite_test_one() function to the list of executable tests. - suite_addTest suite_test_one - - # Call the suite_test_two() function, but note that the test results will not - # be added to the global stats, and therefore not reported at the end of the - # unit test execution. - suite_test_two -} - -suite_test_one() { - assertEquals 1 1 -} - -suite_test_two() { - assertNotEquals 1 2 -} - -# Load and run shUnit2. -. ../shunit2 |