forked from gorilla/mux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
370 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,70 @@ | ||
version: 2.0 | ||
version: 2.1 | ||
|
||
jobs: | ||
# Base test configuration for Go library tests Each distinct version should | ||
# inherit this base, and override (at least) the container image used. | ||
"test": &test | ||
"test": | ||
parameters: | ||
version: | ||
type: string | ||
default: "latest" | ||
golint: | ||
type: boolean | ||
default: true | ||
modules: | ||
type: boolean | ||
default: true | ||
goproxy: | ||
type: string | ||
default: "" | ||
docker: | ||
- image: circleci/golang:latest | ||
- image: "circleci/golang:<< parameters.version >>" | ||
working_directory: /go/src/github.com/gorilla/mux | ||
steps: &steps | ||
# Our build steps: we checkout the repo, fetch our deps, lint, and finally | ||
# run "go test" on the package. | ||
environment: | ||
GO111MODULE: "on" | ||
GOPROXY: "<< parameters.goproxy >>" | ||
steps: | ||
- checkout | ||
# Logs the version in our build logs, for posterity | ||
- run: go version | ||
- run: | ||
name: "Print the Go version" | ||
command: > | ||
go version | ||
- run: | ||
name: "Fetch dependencies" | ||
command: > | ||
go get -t -v ./... | ||
if [[ << parameters.modules >> = true ]]; then | ||
go mod download | ||
export GO111MODULE=on | ||
else | ||
go get -v ./... | ||
fi | ||
# Only run gofmt, vet & lint against the latest Go version | ||
- run: | ||
name: "Run golint" | ||
command: > | ||
if [ "${LATEST}" = true ] && [ -z "${SKIP_GOLINT}" ]; then | ||
if [ << parameters.version >> = "latest" ] && [ << parameters.golint >> = true ]; then | ||
go get -u golang.org/x/lint/golint | ||
golint ./... | ||
fi | ||
- run: | ||
name: "Run gofmt" | ||
command: > | ||
if [[ "${LATEST}" = true ]]; then | ||
if [[ << parameters.version >> = "latest" ]]; then | ||
diff -u <(echo -n) <(gofmt -d -e .) | ||
fi | ||
- run: | ||
name: "Run go vet" | ||
command: > | ||
if [[ "${LATEST}" = true ]]; then | ||
command: > | ||
if [[ << parameters.version >> = "latest" ]]; then | ||
go vet -v ./... | ||
fi | ||
- run: go test -v -race ./... | ||
|
||
"latest": | ||
<<: *test | ||
environment: | ||
LATEST: true | ||
|
||
"1.12": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.12 | ||
|
||
"1.11": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.11 | ||
|
||
"1.10": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.10 | ||
|
||
"1.9": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.9 | ||
|
||
"1.8": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.8 | ||
|
||
"1.7": | ||
<<: *test | ||
docker: | ||
- image: circleci/golang:1.7 | ||
- run: | ||
name: "Run go test (+ race detector)" | ||
command: > | ||
go test -v -race ./... | ||
workflows: | ||
version: 2 | ||
build: | ||
tests: | ||
jobs: | ||
- "latest" | ||
- "1.12" | ||
- "1.11" | ||
- "1.10" | ||
- "1.9" | ||
- "1.8" | ||
- "1.7" | ||
- test: | ||
matrix: | ||
parameters: | ||
version: ["latest", "1.15", "1.14", "1.13", "1.12", "1.11"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +build go1.9 | ||
|
||
package mux | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestSchemeMatchers(t *testing.T) { | ||
router := NewRouter() | ||
router.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { | ||
rw.Write([]byte("hello http world")) | ||
}).Schemes("http") | ||
router.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) { | ||
rw.Write([]byte("hello https world")) | ||
}).Schemes("https") | ||
|
||
assertResponseBody := func(t *testing.T, s *httptest.Server, expectedBody string) { | ||
resp, err := s.Client().Get(s.URL) | ||
if err != nil { | ||
t.Fatalf("unexpected error getting from server: %v", err) | ||
} | ||
if resp.StatusCode != 200 { | ||
t.Fatalf("expected a status code of 200, got %v", resp.StatusCode) | ||
} | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
t.Fatalf("unexpected error reading body: %v", err) | ||
} | ||
if !bytes.Equal(body, []byte(expectedBody)) { | ||
t.Fatalf("response should be hello world, was: %q", string(body)) | ||
} | ||
} | ||
|
||
t.Run("httpServer", func(t *testing.T) { | ||
s := httptest.NewServer(router) | ||
defer s.Close() | ||
assertResponseBody(t, s, "hello http world") | ||
}) | ||
t.Run("httpsServer", func(t *testing.T) { | ||
s := httptest.NewTLSServer(router) | ||
defer s.Close() | ||
assertResponseBody(t, s, "hello https world") | ||
}) | ||
} |
Oops, something went wrong.