Skip to content

Commit ad6d9b5

Browse files
authored
Merge pull request #4 from go-rs/develop
0.0.1-beta.1
2 parents 5444f99 + fcc8f7f commit ad6d9b5

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

api_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
package rest
77

88
import (
9+
"io/ioutil"
10+
"net/http"
11+
"net/http/httptest"
912
"testing"
1013
)
1114

@@ -26,6 +29,12 @@ func validateRoute(fun string, method string, url string, t *testing.T) {
2629
}
2730
}
2831

32+
func TestAPI_Route(t *testing.T) {
33+
a.Route("GET", "/greeting", handle)
34+
35+
validateRoute("Route", "GET", "/greeting", t)
36+
}
37+
2938
func TestAPI_Use(t *testing.T) {
3039
a.Use(handle)
3140

@@ -97,3 +106,30 @@ func TestAPI_Exception(t *testing.T) {
97106
t.Error("API: Exception is not working properly")
98107
}
99108
}
109+
110+
func TestAPI_ServeHTTP(t *testing.T) {
111+
var _api API
112+
113+
_api.Get("/", func(ctx *Context) {
114+
ctx.JSON(`{"message": "Hello World!"}`)
115+
})
116+
117+
dummy := httptest.NewServer(_api)
118+
defer dummy.Close()
119+
120+
res, err := http.Get(dummy.URL)
121+
122+
if err != nil {
123+
t.Error("ServeHTTP error")
124+
}
125+
126+
greeting, err := ioutil.ReadAll(res.Body)
127+
res.Body.Close()
128+
if err != nil {
129+
t.Error("ServeHTTP error")
130+
}
131+
132+
if string(greeting) != `{"message": "Hello World!"}` {
133+
t.Error("Response does not match")
134+
}
135+
}

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.1-alpha.3
1+
0.0.1-beta.1

0 commit comments

Comments
 (0)