summaryrefslogtreecommitdiff
path: root/test/sd_notify_test.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/sd_notify_test.erl')
-rw-r--r--test/sd_notify_test.erl33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/sd_notify_test.erl b/test/sd_notify_test.erl
new file mode 100644
index 0000000..32a8ac6
--- /dev/null
+++ b/test/sd_notify_test.erl
@@ -0,0 +1,33 @@
+-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(_) ->
+ [].