Browse Source

raise coverage for server

tags/v0.9.0
jimzhan 9 years ago
parent
commit
104adb5772
2 changed files with 77 additions and 1 deletions
  1. +1
    -1
      README.md
  2. +76
    -0
      server_test.go

+ 1
- 1
README.md View File

<a href="#"><img alt="rex" src="https://raw.githubusercontent.com/go-rex/rex/assets/images/rex.png" width="160px" height="64px"></a> <a href="#"><img alt="rex" src="https://raw.githubusercontent.com/go-rex/rex/assets/images/rex.png" width="160px" height="64px"></a>
=== ===
[![Build Status](https://travis-ci.org/goanywhere/rex.svg?branch=master)](https://travis-ci.org/goanywhere/rex) [![Coverage](http://gocover.io/_badge/github.com/goanywhere/rex?0)](http://gocover.io/github.com/goanywhere/rex) [![GoDoc](https://godoc.org/github.com/goanywhere/rex?status.svg)](http://godoc.org/github.com/goanywhere/rex)
[![Build Status](https://travis-ci.org/goanywhere/rex.svg?branch=master)](https://travis-ci.org/goanywhere/rex) [![GoDoc](https://godoc.org/github.com/goanywhere/rex?status.svg)](http://godoc.org/github.com/goanywhere/rex)


Rex is a library for modular web development in [Go](http://golang.org/), designed to work directly with net/http. Rex is a library for modular web development in [Go](http://golang.org/), designed to work directly with net/http.



+ 76
- 0
server_test.go View File

"path" "path"
"testing" "testing"


"github.com/goanywhere/env"
mw "github.com/goanywhere/rex/middleware"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
) )


func TestConfigure(t *testing.T) {
Convey("rex.configure", t, func() {
app := New()
app.configure()

So(debug, ShouldBeTrue)
So(port, ShouldEqual, 5000)

env.Set("PORT", 9394)
app.configure()
So(port, ShouldEqual, 5000)
})
}

func TestBuild(t *testing.T) {
Convey("rex.build", t, func() {
app := New()
app.build()

So(len(app.middleware.stack), ShouldEqual, 1)

app.Use(mw.NoCache)
So(len(app.middleware.stack), ShouldEqual, 2)
})
}

func TestRegister(t *testing.T) {
Convey("rex.register", t, func() {
app := New()
app.register("/login", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusAccepted)
w.Header().Set("X-Auth-Server", "rex")
}, "POST")

request, _ := http.NewRequest("POST", "/login", nil)
response := httptest.NewRecorder()
app.ServeHTTP(response, request)
So(response.Code, ShouldEqual, http.StatusAccepted)
So(response.Header().Get("X-Auth-Server"), ShouldEqual, "rex")
})
}

func TestAny(t *testing.T) { func TestAny(t *testing.T) {
app := New() app := New()
app.Any("/", func(w http.ResponseWriter, r *http.Request) { app.Any("/", func(w http.ResponseWriter, r *http.Request) {
}) })
} }


func TestCONNECT(t *testing.T) {
app := New()
app.CONNECT("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

Convey("rex.CONNECT", t, func() {
request, _ := http.NewRequest("CONNECT", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
})
}

func TestTRACE(t *testing.T) {
app := New()
app.TRACE("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Powered-By", "rex")
})

Convey("rex.TRACE", t, func() {
request, _ := http.NewRequest("TRACE", "/", nil)
response := httptest.NewRecorder()

app.ServeHTTP(response, request)

So(response.Header().Get("X-Powered-By"), ShouldEqual, "rex")
})
}

func TestGroup(t *testing.T) { func TestGroup(t *testing.T) {
app := New() app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) { app.GET("/", func(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save