@@ -23,6 +23,8 @@ type MailSuite struct{ BaseSuite }
2323
2424func (suite * MailSuite ) SetupSuite () {
2525 cfg := static .NewConfig ()
26+ port := try .GetFreePort ()
27+ cfg .Api .Port = fmt .Sprintf ("%v" , port )
2628 wd , err := os .Getwd ()
2729 require .NoError (suite .T (), err )
2830 cfg .ConfigFile = path .Join (wd , "mokapi.yaml" )
@@ -47,16 +49,16 @@ func (suite *MailSuite) TestSendMail() {
4749 require .NoError (suite .T (), err )
4850
4951 // test mail API
50- try .GetRequest (suite .T (), "http://localhost:8080 /api/services/mail/Mokapi%20MailServer/mailboxes" , nil ,
52+ try .GetRequest (suite .T (), fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer/mailboxes" , suite . cfg . Api . Port ) , nil ,
5153 try .HasStatusCode (200 ),
5254 try .
HasBody (
`[{"name":"[email protected] ","numMessages":1}]` ),
5355 )
54- try .
GetRequest (
suite .
T (),
"http://localhost:8080 /api/services/mail/Mokapi%20MailServer/mailboxes/[email protected] " ,
nil ,
56+ try .
GetRequest (
suite .
T (),
fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer/mailboxes/[email protected] " , suite . cfg . Api . Port ) ,
nil ,
5557 try .HasStatusCode (200 ),
5658 try .
HasBody (
`{"name":"[email protected] ","numMessages":1,"folders":["INBOX"]}` ),
5759 )
5860 var messageId string
59- try .
GetRequest (
suite .
T (),
"http://localhost:8080 /api/services/mail/Mokapi%20MailServer/mailboxes/[email protected] /messages" ,
nil ,
61+ try .
GetRequest (
suite .
T (),
fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer/mailboxes/[email protected] /messages" , suite . cfg . Api . Port ) ,
nil ,
6062 try .HasStatusCode (200 ),
6163 try .AssertBody (func (t * testing.T , body string ) {
6264 var v any
@@ -73,7 +75,7 @@ func (suite *MailSuite) TestSendMail() {
7375 messageId = m ["messageId" ].(string )
7476 }),
7577 )
76- try .GetRequest (suite .T (), "http://localhost:8080 /api/services/mail/messages/" + messageId , nil ,
78+ try .GetRequest (suite .T (), fmt . Sprintf ( "http://localhost:%v /api/services/mail/messages/%v" , suite . cfg . Api . Port , messageId ) , nil ,
7779 try .HasStatusCode (200 ),
7880 try .AssertBody (func (t * testing.T , body string ) {
7981 var v any
@@ -209,16 +211,16 @@ It can be any text data.
209211 require .NoError (suite .T (), err )
210212
211213 // test mail API
212- try .GetRequest (suite .T (), "http://localhost:8080 /api/services/mail/Mokapi%20MailServer%20Old/mailboxes" , nil ,
214+ try .GetRequest (suite .T (), fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer%% 20Old/mailboxes" , suite . cfg . Api . Port ) , nil ,
213215 try .HasStatusCode (200 ),
214216 try .
HasBody (
`[{"name":"[email protected] ","numMessages":1}]` ),
215217 )
216- try .
GetRequest (
suite .
T (),
"http://localhost:8080 /api/services/mail/Mokapi%20MailServer%20Old/mailboxes/[email protected] " ,
nil ,
218+ try .
GetRequest (
suite .
T (),
fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer%% 20Old/mailboxes/[email protected] " , suite . cfg . Api . Port ) ,
nil ,
217219 try .HasStatusCode (200 ),
218220 try .
HasBody (
`{"name":"[email protected] ","numMessages":1,"folders":["INBOX"]}` ),
219221 )
220222 var messageId string
221- try .
GetRequest (
suite .
T (),
"http://localhost:8080 /api/services/mail/Mokapi%20MailServer%20Old/mailboxes/[email protected] /messages" ,
nil ,
223+ try .
GetRequest (
suite .
T (),
fmt . Sprintf ( "http://localhost:%v /api/services/mail/Mokapi%% 20MailServer%% 20Old/mailboxes/[email protected] /messages" , suite . cfg . Api . Port ) ,
nil ,
222224 try .HasStatusCode (200 ),
223225 try .AssertBody (func (t * testing.T , body string ) {
224226 var v any
@@ -235,7 +237,7 @@ It can be any text data.
235237 messageId = m ["messageId" ].(string )
236238 }),
237239 )
238- try .GetRequest (suite .T (), "http://localhost:8080 /api/services/mail/messages/" + messageId , nil ,
240+ try .GetRequest (suite .T (), fmt . Sprintf ( "http://localhost:%v /api/services/mail/messages/%v" , suite . cfg . Api . Port , messageId ) , nil ,
239241 try .HasStatusCode (200 ),
240242 try .AssertBody (func (t * testing.T , body string ) {
241243 var v any
0 commit comments