obmc-console: Consolidate handling of default socket-id

If console-id is not specified on command line or in the config file
then use the default value. ae2460d0b8e8 ("obmc-console: Provide a
default value for `console-id`.") only implemented the default value for
naming the abstract listening socket and overlooked the new DBus path
naming convention.  This caused issues during dbus registration:

```
obmc-console-server: Object name: /xyz/openbmc_project/console/(null)
obmc-console-server: Failed to issue method call: Invalid argument
```

Fixes: ae2460d0b8e8 ("obmc-console: Provide a default value for `console-id`.")
Change-Id: I6d0f7b23cc085992189cd4463129a6aae590b3e7
Signed-off-by: Ninad Palsule <ninadpalsule@us.ibm.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/test-config-resolve-console-id.c b/test/test-config-resolve-console-id.c
new file mode 100644
index 0000000..319f342
--- /dev/null
+++ b/test/test-config-resolve-console-id.c
@@ -0,0 +1,140 @@
+#include <assert.h>
+
+#define TEST_CONSOLE_ID "test"
+
+#include "config.c"
+
+static void test_independence_cmdline_optarg(void)
+{
+	const char *console_id;
+	struct config *ctx;
+
+	ctx = calloc(1, sizeof(*ctx));
+	console_id = config_resolve_console_id(ctx, TEST_CONSOLE_ID);
+
+	assert(!strcmp(console_id, TEST_CONSOLE_ID));
+
+	config_fini(ctx);
+}
+
+static void test_independence_config_console_id(void)
+{
+	const char *console_id;
+	struct config *ctx;
+	char *buf;
+
+	ctx = calloc(1, sizeof(*ctx));
+	buf = strdup("console-id = " TEST_CONSOLE_ID);
+	config_parse(ctx, buf);
+	free(buf);
+	console_id = config_resolve_console_id(ctx, NULL);
+
+	assert(!strcmp(console_id, TEST_CONSOLE_ID));
+
+	config_fini(ctx);
+}
+
+static void test_independence_config_socket_id(void)
+{
+	const char *console_id;
+	struct config *ctx;
+	char *buf;
+
+	ctx = calloc(1, sizeof(*ctx));
+	buf = strdup("socket-id = " TEST_CONSOLE_ID);
+	config_parse(ctx, buf);
+	free(buf);
+	console_id = config_resolve_console_id(ctx, NULL);
+
+	assert(!strcmp(console_id, TEST_CONSOLE_ID));
+
+	config_fini(ctx);
+}
+
+static void test_independence_default(void)
+{
+	const char *console_id;
+	struct config *ctx;
+
+	ctx = calloc(1, sizeof(*ctx));
+	console_id = config_resolve_console_id(ctx, NULL);
+
+	assert(!strcmp(console_id, DEFAULT_CONSOLE_ID));
+
+	config_fini(ctx);
+}
+
+static void test_precedence_cmdline_optarg(void)
+{
+	static const char *const config = "console-id = console\n"
+					  "socket-id = socket\n";
+	const char *console_id;
+	struct config *ctx;
+	char *buf;
+
+	ctx = calloc(1, sizeof(*ctx));
+	buf = strdup(config);
+	config_parse(ctx, buf);
+	free(buf);
+	console_id = config_resolve_console_id(ctx, TEST_CONSOLE_ID);
+
+	assert(config_get_value(ctx, "console-id"));
+	assert(config_get_value(ctx, "socket-id"));
+	assert(!strcmp(console_id, TEST_CONSOLE_ID));
+
+	config_fini(ctx);
+}
+
+static void test_precedence_config_console_id(void)
+{
+	static const char *const config = "console-id = console\n"
+					  "socket-id = socket\n";
+	const char *console_id;
+	struct config *ctx;
+	char *buf;
+
+	ctx = calloc(1, sizeof(*ctx));
+	buf = strdup(config);
+	config_parse(ctx, buf);
+	free(buf);
+	console_id = config_resolve_console_id(ctx, NULL);
+
+	assert(config_get_value(ctx, "console-id"));
+	assert(config_get_value(ctx, "socket-id"));
+	assert(!strcmp(console_id, "console"));
+
+	config_fini(ctx);
+}
+
+static void test_precedence_config_socket_id(void)
+{
+	static const char *const config = "socket-id = socket\n";
+	const char *console_id;
+	struct config *ctx;
+	char *buf;
+
+	ctx = calloc(1, sizeof(*ctx));
+	buf = strdup(config);
+	config_parse(ctx, buf);
+	free(buf);
+	console_id = config_resolve_console_id(ctx, NULL);
+
+	assert(!config_get_value(ctx, "console-id"));
+	assert(config_get_value(ctx, "socket-id"));
+	assert(!strcmp(console_id, "socket"));
+
+	config_fini(ctx);
+}
+
+int main(void)
+{
+	test_independence_cmdline_optarg();
+	test_independence_config_console_id();
+	test_independence_config_socket_id();
+	test_independence_default();
+	test_precedence_cmdline_optarg();
+	test_precedence_config_console_id();
+	test_precedence_config_socket_id();
+
+	return EXIT_SUCCESS;
+}