1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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())),
{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())),
1 = sd_notify:sd_pid_notify_with_fds(0, 0, TestMessage, []),
{ok, {_Address, _Port, Packet}} = gen_udp:recv(FakeNotifyUnixSock, length(TestMessage), 1000),
?assertEqual(TestMessage, Packet)
end
}
]
};
sd_notify_test_local(_) ->
[].
|