File tree 2 files changed +28
-1
lines changed
2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -63,7 +63,6 @@ func New() *Kid {
63
63
// Specifying an address is optional. Default address is :2376.
64
64
func (k * Kid ) Run (address ... string ) error {
65
65
addr := resolveAddress (address )
66
-
67
66
return http .ListenAndServe (addr , k )
68
67
}
69
68
Original file line number Diff line number Diff line change @@ -2,9 +2,11 @@ package kid
2
2
3
3
import (
4
4
"fmt"
5
+ "io"
5
6
"net/http"
6
7
"net/http/httptest"
7
8
"testing"
9
+ "time"
8
10
9
11
"github.com/mojixcoder/kid/errors"
10
12
"github.com/mojixcoder/kid/serializer"
@@ -463,3 +465,29 @@ func TestKidDebug(t *testing.T) {
463
465
k .debug = true
464
466
assert .True (t , k .Debug ())
465
467
}
468
+
469
+ func TestKidRun (t * testing.T ) {
470
+ k := New ()
471
+
472
+ k .GET ("/" , func (c * Context ) error {
473
+ return c .JSON (http .StatusOK , Map {"message" : "healthy" })
474
+ })
475
+
476
+ go func () {
477
+ assert .NoError (t , k .Run ())
478
+ }()
479
+
480
+ // Wait for the server to start
481
+ time .Sleep (5 * time .Millisecond )
482
+
483
+ resp , err := http .Get ("http://localhost:2376" )
484
+ assert .NoError (t , err )
485
+
486
+ defer resp .Body .Close ()
487
+
488
+ body , err := io .ReadAll (resp .Body )
489
+ assert .NoError (t , err )
490
+ assert .Equal (t , http .StatusOK , resp .StatusCode )
491
+ assert .Equal (t , "application/json" , resp .Header .Get ("Content-Type" ))
492
+ assert .Equal (t , "{\" message\" :\" healthy\" }\n " , string (body ))
493
+ }
You can’t perform that action at this time.
0 commit comments