Просмотр исходного кода

raise coverage for server

tags/v0.9.0
jimzhan 9 лет назад
Родитель
Сommit
104adb5772
2 измененных файлов: 77 добавлений и 1 удалений
  1. +1
    -1
      README.md
  2. +76
    -0
      server_test.go

+ 1
- 1
README.md Просмотреть файл

@@ -1,6 +1,6 @@
<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.


+ 76
- 0
server_test.go Просмотреть файл

@@ -8,9 +8,53 @@ import (
"path"
"testing"

"github.com/goanywhere/env"
mw "github.com/goanywhere/rex/middleware"
. "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) {
app := New()
app.Any("/", func(w http.ResponseWriter, r *http.Request) {
@@ -134,6 +178,38 @@ func TestDELETE(t *testing.T) {
})
}

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) {
app := New()
app.GET("/", func(w http.ResponseWriter, r *http.Request) {

Загрузка…
Отмена
Сохранить