ACK. The test works for me.
However, after reading through this test, I'd like to talk about how the
keys functionality works with augeas. I think that we should make what
gets stored in a key file consistent for each type of sysconfig scheme
(puppet, augeaus, regedit).
Right now, the key file is storing the output of the augeas command.
The puppet scheme works differently. I think we should make augeas work
the same way. Right now, when you use run_uri() or run_string() with
puppet, the key file has:
1) "OK" -- successful
2) "FAILED\n%d", process exit code -- failed
For augeaus, since we don't shell out, it won't be the process exit
code, but it could be the return value from the augeas API call.
On 09/27/2011 08:24 AM, Radek Novacek wrote:
The test compares results from mh_sysconfig_query,
mh_sysconfig_run_string and mh_sysconfig_run_uri.
---
src/tests/mh_api_sysconfig.h | 78 ++++++++++++++++++++++++++++++++++++++++++
1 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/src/tests/mh_api_sysconfig.h b/src/tests/mh_api_sysconfig.h
index 5eb4fe7..1cbe18a 100644
--- a/src/tests/mh_api_sysconfig.h
+++ b/src/tests/mh_api_sysconfig.h
@@ -23,6 +23,29 @@ extern "C" {
using namespace std;
+/**
+ * Callback function, doesn't do anything
+ */
+void f(void *, int)
+{
+}
+
+/**
+ * Result from run_string and run_uri functions is in the form "query =
result\n"
+ * This function will extract the "result"
+ *
+ * \note The return of this routine must be freed with free()
+ */
+char *strip(const char *result)
+{
+ char *stripped;
+ // strip the "query = " part
+ stripped = strdup(strstr(result, " = ") + 3);
+ // and the line end
+ stripped[strlen(stripped) - 1] = '\0';
+ return stripped;
+}
+
class MhApiSysconfigSuite : public CxxTest::TestSuite
{
public:
@@ -46,6 +69,61 @@ class MhApiSysconfigSuite : public CxxTest::TestSuite
TS_ASSERT((mh_sysconfig_set_configured(invalid_keys[i], "OK")) ==
FALSE);
}
}
+
+ /**
+ * This test compares result of mh_sysconfig_query, mh_sysconfig_run_string
+ * and mh_sysconfig_run_uri commands.
+ */
+ void testAugeasQuery(void)
+ {
+ const char key[] = "org.matahariproject.test.unittest.augeas";
+ const char query[] = "/files/etc/fstab/1/spec";
+ const char command[] = "get /files/etc/fstab/1/spec";
+ char tmp_file[] = "matahari-sysconfig-test_XXXXXX";
+ char *query_result, *run_string_result, *run_string_result_stripped;
+ char *run_uri_result, *run_uri_result_stripped;
+ char *uri, *abs_path;
+ int fd = mkstemp(tmp_file);
+ TS_ASSERT(fd>= 0);
+
+ // test query function
+ query_result = mh_sysconfig_query(query, 0, "augeas");
+ TS_ASSERT(query_result != NULL);
+ TS_ASSERT(strlen(query_result)> 0);
+
+ // test run_string function
+ TS_ASSERT(mh_sysconfig_run_string(command, MH_SYSCONFIG_FLAG_FORCE,
"augeas", key, f, NULL) == MH_RES_SUCCESS);
+ run_string_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_string_result != NULL);
+
+ run_string_result_stripped = strip(run_string_result);
+ free(run_string_result);
+
+ // test run_uri function
+ write(fd, command, strlen(command));
+ write(fd, "\n", 1);
+ close(fd);
+
+ abs_path = realpath(tmp_file, NULL);
+ asprintf(&uri, "file://%s", abs_path);
+ TS_ASSERT(mh_sysconfig_run_uri(uri, MH_SYSCONFIG_FLAG_FORCE, "augeas",
key, f, NULL) == MH_RES_SUCCESS);
+ run_uri_result = mh_sysconfig_is_configured(key);
+ TS_ASSERT(run_uri_result != NULL);
+
+ run_uri_result_stripped = strip(run_uri_result);
+ free(run_uri_result);
+ unlink(tmp_file);
+
+ // compare the results of all functions above
+ TS_ASSERT(strcmp(query_result, run_string_result_stripped) == 0);
+ TS_ASSERT(strcmp(query_result, run_uri_result_stripped) == 0);
+
+ free(query_result);
+ free(run_string_result_stripped);
+ free(run_uri_result_stripped);
+ free(abs_path);
+ free(uri);
+ }
};
#endif
--
Russell Bryant