mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-06 05:32:01 +00:00
Instead of relying on a custom global_setup and global_teardown functions, migrate to the use of bats' setup_file and teardown_file functions. Signed-off-by: William Douglas <william.douglas@intel.com>
63 lines
1.4 KiB
Bash
Executable File
63 lines
1.4 KiB
Bash
Executable File
#!/usr/bin/env bats
|
|
|
|
load "../testlib"
|
|
|
|
setup_file() {
|
|
|
|
create_test_environment "$TEST_NAME"
|
|
printf "test-data" | sudo tee "$TARGET_DIR"/test-hash > /dev/null
|
|
|
|
}
|
|
|
|
teardown_file() {
|
|
|
|
destroy_test_environment --force "$TEST_NAME"
|
|
|
|
}
|
|
|
|
@test "HSD001: Calculate the hash of a file" {
|
|
|
|
run sudo sh -c "$SWUPD hashdump $TARGET_DIR/test-hash"
|
|
|
|
assert_status_is 0
|
|
expected_output=$(cat <<-EOM
|
|
Calculating hash with xattrs for: .*/target-dir/test-hash
|
|
8286279c93f45c7ffa6b9ed440066de09716527346d9dd0239f50948e0e554f0
|
|
EOM
|
|
)
|
|
assert_regex_is_output "$expected_output"
|
|
|
|
}
|
|
|
|
@test "HSD002: Try calculating the hash of a file that does not exist" {
|
|
|
|
# attempting to calculate the hash from a non existent file should still
|
|
# succeed but should return a hash of all zeros
|
|
|
|
run sudo sh -c "$SWUPD hashdump $TARGET_DIR/fake-file"
|
|
|
|
assert_status_is 0
|
|
expected_output=$(cat <<-EOM
|
|
Calculating hash with xattrs for: .*/target-dir/fake-file
|
|
0000000000000000000000000000000000000000000000000000000000000000
|
|
EOM
|
|
)
|
|
assert_regex_is_output "$expected_output"
|
|
|
|
}
|
|
|
|
@test "HSD003: Calculate the hash of a file specifying its path separatelly" {
|
|
|
|
run sudo sh -c "$SWUPD hashdump --path=$TARGET_DIR test-hash"
|
|
|
|
assert_status_is 0
|
|
expected_output=$(cat <<-EOM
|
|
Calculating hash with xattrs for: .*/target-dir/test-hash
|
|
8286279c93f45c7ffa6b9ed440066de09716527346d9dd0239f50948e0e554f0
|
|
EOM
|
|
)
|
|
assert_regex_is_output "$expected_output"
|
|
|
|
}
|
|
#WEIGHT=2
|