Skip to content

Commit 076eb0f

Browse files
committed
test: add more tests
1 parent 40d249e commit 076eb0f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

kid.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ func New() *Kid {
6363
// Specifying an address is optional. Default address is :2376.
6464
func (k *Kid) Run(address ...string) error {
6565
addr := resolveAddress(address)
66-
6766
return http.ListenAndServe(addr, k)
6867
}
6968

kid_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package kid
22

33
import (
44
"fmt"
5+
"io"
56
"net/http"
67
"net/http/httptest"
78
"testing"
9+
"time"
810

911
"github.com/mojixcoder/kid/errors"
1012
"github.com/mojixcoder/kid/serializer"
@@ -463,3 +465,29 @@ func TestKidDebug(t *testing.T) {
463465
k.debug = true
464466
assert.True(t, k.Debug())
465467
}
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+
}

0 commit comments

Comments
 (0)