Skip to content

Commit

Permalink
Add travis
Browse files Browse the repository at this point in the history
  • Loading branch information
josephspurrier committed Jun 13, 2018
1 parent d305dd7 commit c3cb810
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# OS files
.DS_Store

# Vendor files
/vendor/
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: go

go:
#- 1.0
#- 1.1
#- 1.2
#- 1.3
- 1.4
- 1.5
- 1.6
- 1.7
- 1.8
- 1.9
- 1.10
- tip

before_install:
- go get github.com/axw/gocov/gocov
- go get github.com/mattn/goveralls
- go get golang.org/x/tools/cmd/cover

script:
- $HOME/gopath/bin/goveralls
7 changes: 7 additions & 0 deletions h.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ type F func(http.ResponseWriter, *http.Request) (int, error)
// F.ServeHTTP.
var ServeHTTP = func(w http.ResponseWriter, r *http.Request, status int,
err error) {
if status >= 400 {
if err != nil {
http.Error(w, err.Error(), status)
} else {
http.Error(w, "", status)
}
}
}

// ServeHTTP calls f(w, r) and passes the result to h.ServeHTTP.
Expand Down
33 changes: 33 additions & 0 deletions h_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package h_test

import (
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/josephspurrier/h"
"github.com/stretchr/testify/assert"
)

func TestServeHTTPResponseOK(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r, http.StatusOK, nil)
assert.Equal(t, http.StatusOK, w.Code)
}

func TestServeHTTPResponseIgnoreLessThan200(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r, http.StatusCreated, nil)
assert.Equal(t, http.StatusOK, w.Code)
}

func TestServeHTTPResponseError(t *testing.T) {
r := httptest.NewRequest("GET", "/", nil)
w := httptest.NewRecorder()
h.ServeHTTP(w, r, http.StatusInternalServerError, errors.New("error happened"))
assert.Equal(t, http.StatusInternalServerError, w.Code)
assert.Contains(t, w.Body.String(), "error happened")
}

0 comments on commit c3cb810

Please sign in to comment.