Commit Graph

17 Commits

Author SHA1 Message Date
Jonatan Schlag
0d61c6807c initscripts fkt: Check that readhash returns 1 on a missing file
It already does that, so the function is not changed

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
14ecdd86f1 initscripts fkt: keep readhash compatible with older implementation
With the use of eval BLUE_DEV='blue0 net0' stored "blue0 net0" in the
variable BLUE_DEV not "'blue0 net0'"

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
f1d94e7457 initscripts fkt: readhash should only parse lines with a =
A line without a = is clearly invalid.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
9f72b7bc5f initscripts fkt: Check for invalid values in readhash
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
02254f5543 initscripts fkt: ignore invalid keys in readhash
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
d289bc28be initscripts fkt: Ignore comments in readhash
As '#Another Comment' is a valid key we test this change by checking if
the comments do not end up as keys in our array.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
59e3c2a217 initscript fkt: ignore blank lines in readhash
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
96bb3ba8b8 initscript functions: add readhash
To avoid the usage of eval and to store the config in an key value
array, we introduce an new function. The tests only check if we
read the correct value to the correct variable.

One comment on the implementation as this has created some headache:

>From https://www.gnu.org/software/bash/manual/bash.html#Bourne-Shell-Builtins

	"When used in a function, declare makes each name local, as with the local command, unless the -g option is used."

So we need to use -g here

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
acde9c1a13 tests: Add functions test_that_array_doesnt_have_key
Apparently we can set way more keys then I expected. So we need a
function to check that we do not set certain key. Some keys need to be
skipped.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
644b91e302 test: Add functions test_that_array_is_defined
we need this check in multiple places so it makes sense to move this to
a separate function.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
8f4c1855fa tests: Add function to test the ouput of a bash function
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
721373c3d7 test_value_in_array: Check if the key is defined
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
7631871fa9 tests/lib.sh: adjust to pytest logging style
Black on white is still the best to read. So we only style FAILED or
PASSED in green or red. This is also tested with different background
colors. As we only style PASSED or FAILED it works without any problems

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
1579e8b3fc tests/lib.sh: Add logging functions
So we can change the style of our log messages better.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
035f866d75 tests/lib.sh: Add check if variable exists to test_value_in_array
We cannot use [ -v ] here as this does not work. We need to check if the
array is correctly declared.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
dae8a08086 tests/lib.sh: Add function test_value_in_array
Test if a given array has the specified value stored under key.

! does not work here to access the array by variable name. So the solution here is:
https://unix.stackexchange.com/questions/60584/how-to-use-a-variable-as-part-of-an-array-name/60585#60585

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00
Jonatan Schlag
6f4e782356 tests: Add bash lib
This allows use to write test with less effort as we can reuse functions

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
2024-08-24 12:19:56 +00:00