Skip to content

Commit

Permalink
Merge pull request #170 from matthewrudy/testing
Browse files Browse the repository at this point in the history
Add Travis and Fix the tests
  • Loading branch information
nateberkopec authored Aug 21, 2019
2 parents 70121c7 + d6656e0 commit 338eacc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: go

go:
- "1.10.x"
- master

os:
- linux
- osx

install:
- go get -t ./...

script:
- make test
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ release:
mv puma-dev_darwin_amd64 puma-dev
zip puma-dev-$$RELEASE-darwin-amd64.zip puma-dev

test:
go test -v ./...

.PHONY: all release
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Puma-dev: A fast, zero-config development server for OS X and Linux

[![Build Status](https://travis-ci.org/puma/puma-dev.svg?branch=master)](https://travis-ci.org/puma/puma-dev)

Puma-dev is the emotional successor to pow. It provides a quick and easy way to manage apps in development on OS X and Linux.

## Highlights
Expand Down
2 changes: 1 addition & 1 deletion httputil/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ExampleDumpRequest() {
fmt.Printf("%s", b)

// Output:
// "POST / HTTP/1.1\r\nHost: www.example.org\r\nAccept-Encoding: gzip\r\nUser-Agent: Go-http-client/1.1\r\n\r\nGo is a general-purpose language designed with systems programming in mind."
// "POST / HTTP/1.1\r\nHost: www.example.org\r\nAccept-Encoding: gzip\r\nContent-Length: 75\r\nUser-Agent: Go-http-client/1.1\r\n\r\nGo is a general-purpose language designed with systems programming in mind."
}

func ExampleDumpRequestOut() {
Expand Down
46 changes: 16 additions & 30 deletions httputil/reverseproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,36 +298,6 @@ func req(t *testing.T, v string) *http.Request {
return req
}

// Issue 12344
func TestNilBody(t *testing.T) {
backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hi"))
}))
defer backend.Close()

frontend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
backURL, _ := url.Parse(backend.URL)
rp := NewSingleHostReverseProxy(backURL)
r := req(t, "GET / HTTP/1.0\r\n\r\n")
r.Body = nil // this accidentally worked in Go 1.4 and below, so keep it working
rp.ServeHTTP(w, r)
}))
defer frontend.Close()

res, err := http.Get(frontend.URL)
if err != nil {
t.Fatal(err)
}
defer res.Body.Close()
slurp, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if string(slurp) != "hi" {
t.Errorf("Got %q; want %q", slurp, "hi")
}
}

type bufferPool struct {
get func() []byte
put func([]byte)
Expand Down Expand Up @@ -432,3 +402,19 @@ func TestReverseProxy_Post(t *testing.T) {
t.Errorf("got body %q; expected %q", g, e)
}
}

func NewSingleHostReverseProxy(target *url.URL) *ReverseProxy {
targetQuery := target.RawQuery
director := func(res http.ResponseWriter, req *http.Request) error {
req.URL.Scheme = target.Scheme
req.URL.Host = target.Host
req.URL.Path = singleJoiningSlash(target.Path, req.URL.Path)
if targetQuery == "" || req.URL.RawQuery == "" {
req.URL.RawQuery = targetQuery + req.URL.RawQuery
} else {
req.URL.RawQuery = targetQuery + "&" + req.URL.RawQuery
}
return nil
}
return &ReverseProxy{Proxy: director}
}

0 comments on commit 338eacc

Please sign in to comment.