Skip to content

Commit

Permalink
ref: Implement redirect path tests
Browse files Browse the repository at this point in the history
  • Loading branch information
azubieta committed Mar 31, 2022
1 parent bf1bf54 commit c7a02dc
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/hooks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ add_executable(exec_utils_tests ./exec_utils_tests.c)
target_link_libraries(exec_utils_tests PRIVATE apprun_hooks ${CHECK_LIBRARIES} pthread)
add_test(NAME TEST_EXEC_UTILS COMMAND exec_utils_tests)

add_executable(redirect_path_tests ./redirect_path_tests.c)
target_link_libraries(redirect_path_tests PRIVATE apprun_hooks ${CHECK_LIBRARIES} pthread)
add_test(NAME TEST_REDIRECT_PATH COMMAND redirect_path_tests)

add_executable(environment_test environment_test.c ../common/tests_shared.c $<TARGET_OBJECTS:common_objects>)
target_link_libraries(environment_test apprun_hooks)
add_test(NAME TEST_ENVIRONMENT COMMAND environment_test)
Expand Down
44 changes: 44 additions & 0 deletions test/hooks/redirect_path_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <check.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

#include "hooks/redirect_path.h"
#include "common/appdir_environment.h"

START_TEST (test_redirect_path_full)
{
setenv(APPDIR_PATH_MAPPINGS_ENV, "/fake_tmp:/tmp;", 1);
char *result = apprun_redirect_path("/fake_tmp");
ck_assert_str_eq(result, "/tmp");
unsetenv(APPDIR_PATH_MAPPINGS_ENV);
}
END_TEST

Suite *redirect_path_suite(void) {
Suite *s;
TCase *tc_redirect_path;

s = suite_create("Exec Utils");

/* Core test case */
tc_redirect_path = tcase_create("redirect_path_full");
tcase_add_test(tc_redirect_path, test_redirect_path_full);
suite_add_tcase(s, tc_redirect_path);

return s;
}

int main(void) {
int number_failed;
Suite *s;
SRunner *sr;

s = redirect_path_suite();
sr = srunner_create(s);

srunner_run_all(sr, CK_NORMAL);
number_failed = srunner_ntests_failed(sr);
srunner_free(sr);
return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}

0 comments on commit c7a02dc

Please sign in to comment.