Repository: ORNL/DataFed (language: python)

Issue:
[CI, Build] - Create unit tests for authz C/C++ library
# Description

The authz library has not unit tests associated with it this makes it very difficult and time consuming to debug.

# Acceptance

- Working CMake unit tests that can be run to test the internal of the authz library.


Discussion / hints:
Depends on https://github.com/ORNL/DataFed/issues/1156

Trivial placeholder demonstrating correct integration in CMake

```
cmake --build build -j3
[ 18%] Built target protobuf-target
[ 18%] Built target datafed-protobuf
[ 43%] Built target common
[ 46%] Built target unit_test_DynaLog
[ 47%] Built target unit_test_SocketOptions
[ 50%] Built target unit_test_SocketFactory
[ 52%] Built target unit_test_Buffer
[ 56%] Built target unit_test_ProxyBasicZMQ
[ 56%] Built target unit_test_Frame
[ 58%] Built target unit_test_OperatorFactory
[ 60%] Built target unit_test_ProtoBufMap
[ 62%] Built target unit_test_Value
[ 64%] Built target unit_test_MessageFactory
[ 66%] Built target unit_test_CommunicatorFactory
[ 68%] Built target unit_test_Proxy
[ 70%] Built target unit_test_ProtoBufFactory
[ 71%] Built target test_tcp_secure_client
[ 73%] Built target test_tcp_secure_server
Scanning dependencies of target datafed-core-lib
Scanning dependencies of target datafed-authz
[ 78%] Built target datafed-repo
[ 79%] Building CXX object core/server/CMakeFiles/datafed-core-lib.dir/TaskWorker.cpp.o
[ 80%] Building CXX object repository/gridftp/globus5/authz/source/CMakeFiles/datafed-authz.dir/AuthzWorker.cpp.o
[ 81%] Building C object repository/gridftp/globus5/authz/source/CMakeFiles/datafed-authz.dir/libauthz.c.o
[ 82%] Linking CXX shared library libdatafed-authz.so
[ 83%] Linking CXX static library libdatafed-core-lib.a
[ 91%] Built target datafed-core-lib
[ 92%] Linking CXX executable unit_test_AuthMap
[ 93%] Linking CXX executable datafed-core
[ 93%] Built target datafed-authz
[ 94%] Linking CXX executable unit_test_AuthenticationManager
[ 95%] Built target unit_test_AuthMap
Scanning dependencies of target unit_test_getVersion
[ 96%] Building CXX object repository/gridftp/globus5/authz/tests/unit/CMakeFiles/unit_test_getVersion.dir/test_getVersion.cpp.o
[ 97%] Built target unit_test_AuthenticationManager
[ 98%] Built target datafed-core
[100%] Linking CXX executable unit_test_getVersion
[100%] Built target unit_test_getVersion
```

unit_test_getVersion is built

```
ctest -R getVersion
Test project /home/cloud/nfs/DataFed/build
    Start 18: unit_test_getVersion
1/1 Test #18: unit_test_getVersion .............   Passed    0.05 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.08 sec
```

Fix patch:
diff --git a/repository/gridftp/globus5/authz/CMakeLists.txt b/repository/gridftp/globus5/authz/CMakeLists.txt
index 668592821..5cb4485cf 100644
--- a/repository/gridftp/globus5/authz/CMakeLists.txt
+++ b/repository/gridftp/globus5/authz/CMakeLists.txt
@@ -1,1 +1,5 @@
 add_subdirectory( source )
+
+if( BUILD_AUTHZ_TESTS )
+  add_subdirectory( tests )
+endif()


Test patch:
diff --git a/repository/gridftp/globus5/authz/tests/CMakeLists.txt b/repository/gridftp/globus5/authz/tests/CMakeLists.txt
new file mode 100644
index 000000000..932023f93
--- /dev/null
+++ b/repository/gridftp/globus5/authz/tests/CMakeLists.txt
@@ -0,0 +1,3 @@
+if( ENABLE_UNIT_TESTS )
+  add_subdirectory(unit)
+endif()
diff --git a/repository/gridftp/globus5/authz/tests/unit/CMakeLists.txt b/repository/gridftp/globus5/authz/tests/unit/CMakeLists.txt
new file mode 100644
index 000000000..efa0e054c
--- /dev/null
+++ b/repository/gridftp/globus5/authz/tests/unit/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Each test listed in Alphabetical order
+foreach(PROG
+    test_getVersion
+)
+
+  file(GLOB ${PROG}_SOURCES ${PROG}*.cpp)
+  add_executable(unit_${PROG} ${${PROG}_SOURCES})
+
+  target_link_libraries(unit_${PROG} PUBLIC datafed-authz ${DATAFED_BOOST_LIBRARIES} ${DATAFED_GSSAPI_LIBRARIES} ${DATAFED_GLOBUS_COMMON_LIBRARIES})
+  target_include_directories(unit_${PROG}  PRIVATE ${DataFed_SOURCE_DIR}/repository/gridftp/globus5/authz/source)
+  if(BUILD_SHARED_LIBS)
+    target_compile_definitions(unit_${PROG} PRIVATE BOOST_TEST_DYN_LINK)
+  endif()
+  add_test(unit_${PROG} unit_${PROG})
+
+endforeach(PROG)
diff --git a/repository/gridftp/globus5/authz/tests/unit/test_getVersion.cpp b/repository/gridftp/globus5/authz/tests/unit/test_getVersion.cpp
new file mode 100644
index 000000000..879358573
--- /dev/null
+++ b/repository/gridftp/globus5/authz/tests/unit/test_getVersion.cpp
@@ -0,0 +1,30 @@
+#define BOOST_TEST_MAIN
+
+#define BOOST_TEST_MODULE getVersion
+#include <boost/filesystem.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include "Version.hpp"
+
+extern "C" {
+#include "AuthzWorker.h"
+}
+
+BOOST_AUTO_TEST_SUITE(get_version)
+
+BOOST_AUTO_TEST_CASE(test_get_version) {
+  // Simulate expected version from SDMS::authz::version
+  const int expected_major = SDMS::authz::version::MAJOR;
+  const int expected_minor = SDMS::authz::version::MINOR;
+  const int expected_patch = SDMS::authz::version::PATCH;
+
+  // Construct the expected version string
+  std::string expected_version = std::to_string(expected_major) + "." +
+                                 std::to_string(expected_minor) + "." +
+                                 std::to_string(expected_patch);
+
+  // Call the function and verify the result
+  BOOST_CHECK_EQUAL(std::string(getVersion()), expected_version);
+}
+
+BOOST_AUTO_TEST_SUITE_END()