-module(sd_notify_test).

-include_lib("eunit/include/eunit.hrl").


sd_notify_test_() ->
	sd_notify_test_local(erlang:system_info(otp_release)).

sd_notify_test_local("19") ->
	{ok, CWD} = file:get_cwd(),
	FakeNotifyUnixSockName = CWD ++ "/fake-notify-udp-sock-" ++ integer_to_list(erlang:phash2(make_ref())),
	TestMessage = integer_to_list(erlang:phash2(make_ref())),
	{ok, FakeNotifyUnixSock} = gen_udp:open(0, [{ifaddr, {local, FakeNotifyUnixSockName}}, {active, false}, list]),
	os:putenv("NOTIFY_SOCKET", FakeNotifyUnixSockName),

	{setup,
		fun() -> ok end,
		fun(_) -> ok = gen_udp:close(FakeNotifyUnixSock), ok = file:delete(FakeNotifyUnixSockName)  end,
		[
			{
				"Try sending message",
				fun() ->
					sd_notify:sd_pid_notify_with_fds(0, 0, TestMessage, [1, 2, 3]),
					{ok, {_Address, _Port, Packet}} = gen_udp:recv(FakeNotifyUnixSock, length(TestMessage), 1000),
					?assertEqual(TestMessage, Packet)
				end
			}

		]

	};
sd_notify_test_local(_) ->
	[].

-module(sd_notify_test).

-include_lib("eunit/include/eunit.hrl").


sd_notify_test_() ->
	sd_notify_test_local(erlang:system_info(otp_release)).

sd_notify_test_local("19") ->
	{ok, CWD} = file:get_cwd(),
	FakeNotifyUnixSockName = CWD ++ "/fake-notify-udp-sock-" ++ integer_to_list(erlang:phash2(make_ref())),
	{ok, FakeNotifyUnixSock} = gen_udp:open(0, [{ifaddr, {local, FakeNotifyUnixSockName}}, {active, false}, list]),
	os:putenv("NOTIFY_SOCKET", FakeNotifyUnixSockName),

	{setup,
		fun() -> ok end,
		fun(_) -> ok = gen_udp:close(FakeNotifyUnixSock), ok = file:delete(FakeNotifyUnixSockName)  end,
		[
			{
				"Try sending message",
				fun() ->
					TestMessage = integer_to_list(erlang:phash2(make_ref())),
					sd_notify:sd_pid_notify_with_fds(0, 0, TestMessage, [1, 2, 3]),
					{ok, {_Address, _Port, Packet}} = gen_udp:recv(FakeNotifyUnixSock, length(TestMessage), 1000),
					?assertEqual(TestMessage, Packet)
				end
			}

		]

	};
sd_notify_test_local(_) ->
	[].

Move test message creation to where it belongs
Move test message creation to where it belongs

Signed-off-by: Peter Lemenkov <2f981fc861bda8c748898150c942841af4296212@redhat.com>
