common: split inventory association function

Create Software::createInventoryAssociation to split the
object mapper call from actually creating the association.

This makes unit testing the functions easier and provides a clean
separation between the logic provided by common code versus the external
information we are fetching.

Tested: Inspection only.

Change-Id: I0147480219b9c9fbc709699b9e50411fb11bea6e
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/common/src/software.cpp b/common/src/software.cpp
index d20451d..1554b05 100644
--- a/common/src/software.cpp
+++ b/common/src/software.cpp
@@ -74,22 +74,28 @@
         co_return;
     }
 
+    createInventoryAssociation(isRunning, endpoint);
+}
+
+void Software::createInventoryAssociation(bool isRunning,
+                                          std::string objectPath)
+{
     std::vector<std::tuple<std::string, std::string, std::string>> assocs;
 
     if (isRunning)
     {
         debug("{SWID}: creating 'running' association to {OBJPATH}", "SWID",
-              swid, "OBJPATH", endpoint);
+              swid, "OBJPATH", objectPath);
         std::tuple<std::string, std::string, std::string> assocRunning = {
-            "running", "ran_on", endpoint};
+            "running", "ran_on", objectPath};
         assocs.push_back(assocRunning);
     }
     else
     {
         debug("{SWID}: creating 'activating' association to {OBJPATH}", "SWID",
-              swid, "OBJPATH", endpoint);
+              swid, "OBJPATH", objectPath);
         std::tuple<std::string, std::string, std::string> assocActivating = {
-            "activating", "activated_on", endpoint};
+            "activating", "activated_on", objectPath};
         assocs.push_back(assocActivating);
     }
 
@@ -99,15 +105,12 @@
     }
     else
     {
-        std::string path = objectPath;
         associationDefinitions =
             std::make_unique<SoftwareAssociationDefinitions>(
-                ctx, path.c_str(),
+                ctx, Software::objectPath.str.c_str(),
                 SoftwareAssociationDefinitions::properties_t{assocs});
         associationDefinitions->emit_added();
     }
-
-    co_return;
 }
 
 void Software::setVersion(const std::string& versionStr,