@@ -45,85 +45,79 @@ cleanup(#{started_by_test := false}) ->
4545% %====================================================================
4646
4747test_generate_cookie (_Config ) ->
48- Cookie = gsmlg_epmd_cookie : generate_cookie (),
49-
50- % % Cookie should be binary
51- ? assert (is_binary (Cookie )),
52-
53- % % Cookie should be 32 bytes (256 bits )
54- ? assertEqual ( 32 , byte_size ( Cookie )) .
48+ { " Generate cookie test " , fun () ->
49+ Cookie = gsmlg_epmd_cookie : generate_cookie (),
50+ % % Cookie should be binary
51+ ? assert (is_binary (Cookie )),
52+ % % Cookie should be 32 bytes (256 bits)
53+ ? assertEqual ( 32 , byte_size ( Cookie ) )
54+ end } .
5555
5656test_cookie_uniqueness (_Config ) ->
57- % % Generate multiple cookies
58- Cookies = [gsmlg_epmd_cookie :generate_cookie () || _ <- lists :seq (1 , 100 )],
59-
60- % % All should be unique
61- UniqueCount = length (lists :usort (Cookies )),
62- ? assertEqual (100 , UniqueCount ).
57+ {" Cookie uniqueness test" , fun () ->
58+ % % Generate multiple cookies
59+ Cookies = [gsmlg_epmd_cookie :generate_cookie () || _ <- lists :seq (1 , 100 )],
60+ % % All should be unique
61+ UniqueCount = length (lists :usort (Cookies )),
62+ ? assertEqual (100 , UniqueCount )
63+ end }.
6364
6465test_cookie_length (_Config ) ->
65- % % Generate 1000 cookies and verify all are 32 bytes
66- Cookies = [ gsmlg_epmd_cookie : generate_cookie () || _ <- lists : seq ( 1 , 1000 )],
67-
68- AllCorrectLength = lists :all (fun (Cookie ) ->
69- byte_size (Cookie ) =:= 32
70- end , Cookies ),
71-
72- ? assert ( AllCorrectLength ) .
66+ { " Cookie length test " , fun () ->
67+ % % Generate 1000 cookies and verify all are 32 bytes
68+ Cookies = [ gsmlg_epmd_cookie : generate_cookie () || _ <- lists : seq ( 1 , 1000 )],
69+ AllCorrectLength = lists :all (fun (Cookie ) ->
70+ byte_size (Cookie ) =:= 32
71+ end , Cookies ),
72+ ? assert ( AllCorrectLength )
73+ end } .
7374
7475test_store_and_retrieve_cookie (_Config ) ->
75- Node = 'test@localhost' ,
76- Cookie = gsmlg_epmd_cookie :generate_cookie (),
77-
78- % % Store cookie
79- ok = gsmlg_epmd_cookie :store_cookie (Node , Cookie ),
80-
81- % % Retrieve cookie
82- {ok , Retrieved } = gsmlg_epmd_cookie :get_cookie (Node ),
83-
84- % % Should match
85- ? assertEqual (Cookie , Retrieved ).
76+ {" Store and retrieve cookie test" , fun () ->
77+ Node = 'test@localhost' ,
78+ Cookie = gsmlg_epmd_cookie :generate_cookie (),
79+ % % Store cookie
80+ ok = gsmlg_epmd_cookie :store_cookie (Node , Cookie ),
81+ % % Retrieve cookie
82+ {ok , Retrieved } = gsmlg_epmd_cookie :get_cookie (Node ),
83+ % % Should match
84+ ? assertEqual (Cookie , Retrieved )
85+ end }.
8686
8787test_format_hello_message (_Config ) ->
88- Node = 'testnode@localhost' ,
89- Cookie = gsmlg_epmd_cookie :generate_cookie (),
90- DistPort = 8001 ,
91-
92- Hello = gsmlg_epmd_cookie :format_hello (Node , Cookie , DistPort ),
93-
94- % % Should be binary
95- ? assert (is_binary (Hello )),
96-
97- % % Should start with version byte
98- <<Version :8 , _Rest /binary >> = Hello ,
99- ? assertEqual (1 , Version ), % % Protocol version 1
100-
101- % % Should be parseable
102- {ok , Parsed } = gsmlg_epmd_cookie :parse_hello (Hello ),
103- ? assertMatch (#{
104- node := Node ,
105- cookie := Cookie ,
106- dist_port := DistPort
107- }, Parsed ).
88+ {" Format hello message test" , fun () ->
89+ Node = 'testnode@localhost' ,
90+ Cookie = gsmlg_epmd_cookie :generate_cookie (),
91+ DistPort = 8001 ,
92+ Hello = gsmlg_epmd_cookie :format_hello (Node , Cookie , DistPort ),
93+ % % Should be binary
94+ ? assert (is_binary (Hello )),
95+ % % Should start with version byte
96+ <<Version :8 , _Rest /binary >> = Hello ,
97+ ? assertEqual (1 , Version ), % % Protocol version 1
98+ % % Should be parseable
99+ {ok , Parsed } = gsmlg_epmd_cookie :parse_hello (Hello ),
100+ ? assertMatch (#{
101+ node := Node ,
102+ cookie := Cookie ,
103+ dist_port := DistPort
104+ }, Parsed )
105+ end }.
108106
109107test_parse_hello_message (_Config ) ->
110- % % Create a valid hello message
111- Node = 'node@host' ,
112- Cookie = crypto :strong_rand_bytes (32 ),
113- DistPort = 8080 ,
114-
115- Hello = gsmlg_epmd_cookie :format_hello (Node , Cookie , DistPort ),
116-
117- % % Parse it
118- {ok , Parsed } = gsmlg_epmd_cookie :parse_hello (Hello ),
119-
120- % % Verify fields
121- ? assertEqual (Node , maps :get (node , Parsed )),
122- ? assertEqual (Cookie , maps :get (cookie , Parsed )),
123- ? assertEqual (DistPort , maps :get (dist_port , Parsed )),
124-
125- % % Verify version
126- ? assertEqual (1 , maps :get (version , Parsed )).
108+ {" Parse hello message test" , fun () ->
109+ % % Create a valid hello message
110+ Node = 'node@host' ,
111+ Cookie = crypto :strong_rand_bytes (32 ),
112+ DistPort = 8080 ,
113+ Hello = gsmlg_epmd_cookie :format_hello (Node , Cookie , DistPort ),
114+ % % Parse it
115+ {ok , Parsed } = gsmlg_epmd_cookie :parse_hello (Hello ),
116+ % % Verify fields
117+ ? assertEqual (Node , maps :get (node , Parsed )),
118+ ? assertEqual (Cookie , maps :get (cookie , Parsed )),
119+ ? assertEqual (DistPort , maps :get (dist_port , Parsed ))
120+ end }.
127121
128122% %====================================================================
129123% % Additional Tests for Error Cases
0 commit comments