Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: migrate from Travis to GitHub Actions #189

Merged
merged 5 commits into from Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/go.yml
@@ -0,0 +1,45 @@
name: Go
on:
push:
branches: [master]
pull_request:
env:
GOPROXY: "https://proxy.golang.org"

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run golangci-lint
uses: actions-contrib/golangci-lint@v1

test:
name: Test
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Run unit tests
run: go test -v -race -coverprofile=coverage -covermode=atomic ./...
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v1.0.6
with:
file: ./coverage
flags: unittests
- name: Cache downloaded modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

8 changes: 6 additions & 2 deletions README.md
@@ -1,5 +1,9 @@
Macaron [![Build Status](https://travis-ci.org/go-macaron/macaron.svg?branch=v1)](https://travis-ci.org/go-macaron/macaron)
=======================
# Macaron

[![GitHub Workflow Status](https://img.shields.io/github/workflow/status/go-macaron/macaron/Go?logo=github&style=for-the-badge)](https://github.com/go-macaron/macaron/actions?query=workflow%3AGo)
[![codecov](https://img.shields.io/codecov/c/github/go-macaron/macaron/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-macaron/macaron)
[![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/gopkg.in/macaron.v1?tab=doc)
[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/go-macaron/macaron)

![Macaron Logo](https://raw.githubusercontent.com/go-macaron/macaron/v1/macaronlogo.png)

Expand Down
6 changes: 3 additions & 3 deletions context.go
Expand Up @@ -31,8 +31,8 @@ import (
"strings"
"time"

"github.com/unknwon/com"
"github.com/go-macaron/inject"
"github.com/unknwon/com"
"golang.org/x/crypto/pbkdf2"
)

Expand Down Expand Up @@ -193,9 +193,9 @@ func (ctx *Context) parseForm() {
contentType := ctx.Req.Header.Get(_CONTENT_TYPE)
if (ctx.Req.Method == "POST" || ctx.Req.Method == "PUT") &&
len(contentType) > 0 && strings.Contains(contentType, "multipart/form-data") {
ctx.Req.ParseMultipartForm(MaxMemory)
_ = ctx.Req.ParseMultipartForm(MaxMemory)
} else {
ctx.Req.ParseForm()
_ = ctx.Req.ParseForm()
}
}

Expand Down
20 changes: 13 additions & 7 deletions context_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
"runtime"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -176,23 +177,23 @@ func Test_Context(t *testing.T) {
m.Get("/:arg/:param/:flag", func(ctx *Context) string {
kvs := make([]string, 0, len(ctx.AllParams()))
for k, v := range ctx.AllParams() {
kvs = append(kvs, k + "=" + v)
kvs = append(kvs, k+"="+v)
}
sort.Strings(kvs)
return strings.Join(kvs, ",")
})

resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/1/2/3", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp,req)
m.ServeHTTP(resp, req)
So(resp.Body.String(), ShouldEqual, ":arg=1,:flag=3,:param=2")
})

Convey("Get file", func() {
m.Post("/getfile", func(ctx *Context) {
ctx.Query("")
ctx.GetFile("hi")
_, _, _ = ctx.GetFile("hi")
})

resp := httptest.NewRecorder()
Expand Down Expand Up @@ -311,7 +312,12 @@ func Test_Context(t *testing.T) {
req, err = http.NewRequest("GET", "/file3", nil)
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
So(resp.Body.String(), ShouldEqual, "open 404.tmpl: no such file or directory\n")

if runtime.GOOS == "windows" {
So(resp.Body.String(), ShouldEqual, "open 404.tmpl: The system cannot find the file specified.\n")
} else {
So(resp.Body.String(), ShouldEqual, "open 404.tmpl: no such file or directory\n")
}
So(resp.Code, ShouldEqual, 500)
})

Expand Down Expand Up @@ -381,7 +387,7 @@ func Test_Context_Redirect(t *testing.T) {
ctx.Redirect("two")

So(resp.Code, ShouldEqual, http.StatusFound)
So(resp.HeaderMap["Location"][0], ShouldEqual, "/path/two")
So(resp.Result().Header["Location"][0], ShouldEqual, "/path/two")
})

Convey("Context with custom redirect", t, func() {
Expand All @@ -400,6 +406,6 @@ func Test_Context_Redirect(t *testing.T) {
ctx.Redirect("two", 307)

So(resp.Code, ShouldEqual, http.StatusTemporaryRedirect)
So(resp.HeaderMap["Location"][0], ShouldEqual, "/path/two")
So(resp.Result().Header["Location"][0], ShouldEqual, "/path/two")
})
}
2 changes: 1 addition & 1 deletion macaron_test.go
Expand Up @@ -138,7 +138,7 @@ func Test_Macaron_EarlyWrite(t *testing.T) {
m := New()
m.Use(func(res http.ResponseWriter) {
result += "foobar"
res.Write([]byte("Hello world"))
_, _ = res.Write([]byte("Hello world"))
})
m.Use(func() {
result += "bat"
Expand Down
2 changes: 1 addition & 1 deletion recovery.go
Expand Up @@ -153,7 +153,7 @@ func Recovery() Handler {

res.WriteHeader(http.StatusInternalServerError)
if nil != body {
res.Write(body)
_, _ = res.Write(body)
}
}
}()
Expand Down
4 changes: 2 additions & 2 deletions recovery_test.go
Expand Up @@ -46,7 +46,7 @@ func Test_Recovery(t *testing.T) {
So(err, ShouldBeNil)
m.ServeHTTP(resp, req)
So(resp.Code, ShouldEqual, http.StatusInternalServerError)
So(resp.HeaderMap.Get("Content-Type"), ShouldEqual, "text/html")
So(resp.Header().Get("Content-Type"), ShouldEqual, "text/html")
So(buf.String(), ShouldNotBeEmpty)
})

Expand All @@ -68,7 +68,7 @@ func Test_Recovery(t *testing.T) {
m.ServeHTTP(resp, req)

So(resp2.Code, ShouldEqual, http.StatusInternalServerError)
So(resp2.HeaderMap.Get("Content-Type"), ShouldEqual, "text/html")
So(resp2.Header().Get("Content-Type"), ShouldEqual, "text/html")
So(resp2.Body.Len(), ShouldBeGreaterThan, 0)
})
}
15 changes: 7 additions & 8 deletions render.go
Expand Up @@ -36,7 +36,6 @@ import (

const (
_CONTENT_TYPE = "Content-Type"
_CONTENT_LENGTH = "Content-Length"
_CONTENT_BINARY = "application/octet-stream"
_CONTENT_JSON = "application/json"
_CONTENT_HTML = "text/html"
Expand Down Expand Up @@ -200,7 +199,7 @@ func NewTemplateFileSystem(opt RenderOptions, omitData bool) TplFileSystem {
lastDir := dirs[len(dirs)-1]

// We still walk the last (original) directory because it's non-sense we load templates not exist in original directory.
if err = filepath.Walk(lastDir, func(path string, info os.FileInfo, err error) error {
if err = filepath.Walk(lastDir, func(path string, info os.FileInfo, _ error) error {
r, err := filepath.Rel(lastDir, path)
if err != nil {
return err
Expand Down Expand Up @@ -458,9 +457,9 @@ func (r *TplRender) JSON(status int, v interface{}) {
r.Header().Set(_CONTENT_TYPE, _CONTENT_JSON+r.CompiledCharset)
r.WriteHeader(status)
if len(r.Opt.PrefixJSON) > 0 {
r.Write(r.Opt.PrefixJSON)
_, _ = r.Write(r.Opt.PrefixJSON)
}
r.Write(result)
_, _ = r.Write(result)
}

func (r *TplRender) JSONString(v interface{}) (string, error) {
Expand Down Expand Up @@ -494,17 +493,17 @@ func (r *TplRender) XML(status int, v interface{}) {
r.Header().Set(_CONTENT_TYPE, _CONTENT_XML+r.CompiledCharset)
r.WriteHeader(status)
if len(r.Opt.PrefixXML) > 0 {
r.Write(r.Opt.PrefixXML)
_, _ = r.Write(r.Opt.PrefixXML)
}
r.Write(result)
_, _ = r.Write(result)
}

func (r *TplRender) data(status int, contentType string, v []byte) {
if r.Header().Get(_CONTENT_TYPE) == "" {
r.Header().Set(_CONTENT_TYPE, contentType)
}
r.WriteHeader(status)
r.Write(v)
_, _ = r.Write(v)
}

func (r *TplRender) RawData(status int, v []byte) {
Expand Down Expand Up @@ -612,7 +611,7 @@ func (r *TplRender) HTMLString(name string, data interface{}, htmlOpt ...HTMLOpt
func (r *TplRender) Error(status int, message ...string) {
r.WriteHeader(status)
if len(message) > 0 {
r.Write([]byte(message[0]))
_, _ = r.Write([]byte(message[0]))
}
}

Expand Down
15 changes: 10 additions & 5 deletions render_test.go
Expand Up @@ -20,6 +20,7 @@ import (
"html/template"
"net/http"
"net/http/httptest"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -574,6 +575,10 @@ func Test_Render_NoRace(t *testing.T) {
}

func Test_Render_Symlink(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("Skipping testing on Windows")
}

Convey("Render can follow symlinks", t, func() {
m := Classic()
m.Use(Renderer(RenderOptions{
Expand Down Expand Up @@ -661,7 +666,7 @@ func Test_dummyRender(t *testing.T) {
})
m.Get("/jsonstring", func(ctx *Context) {
defer shouldPanic()
ctx.JSONString(nil)
_, _ = ctx.JSONString(nil)
})
m.Get("/rawdata", func(ctx *Context) {
defer shouldPanic()
Expand All @@ -681,19 +686,19 @@ func Test_dummyRender(t *testing.T) {
})
m.Get("/htmlsetstring", func(ctx *Context) {
defer shouldPanic()
ctx.Render.HTMLSetString("", "", nil)
_, _ = ctx.Render.HTMLSetString("", "", nil)
})
m.Get("/htmlstring", func(ctx *Context) {
defer shouldPanic()
ctx.Render.HTMLString("", nil)
_, _ = ctx.Render.HTMLString("", nil)
})
m.Get("/htmlsetbytes", func(ctx *Context) {
defer shouldPanic()
ctx.Render.HTMLSetBytes("", "", nil)
_, _ = ctx.Render.HTMLSetBytes("", "", nil)
})
m.Get("/htmlbytes", func(ctx *Context) {
defer shouldPanic()
ctx.Render.HTMLBytes("", nil)
_, _ = ctx.Render.HTMLBytes("", nil)
})
m.Get("/xml", func(ctx *Context) {
defer shouldPanic()
Expand Down
2 changes: 1 addition & 1 deletion response_writer.go
Expand Up @@ -17,7 +17,6 @@ package macaron
import (
"bufio"
"errors"
"fmt"
"net"
"net/http"
)
Expand Down Expand Up @@ -98,6 +97,7 @@ func (rw *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
return hijacker.Hijack()
}

//nolint
func (rw *responseWriter) CloseNotify() <-chan bool {
return rw.ResponseWriter.(http.CloseNotifier).CloseNotify()
}
Expand Down
10 changes: 5 additions & 5 deletions response_writer_test.go
Expand Up @@ -68,7 +68,7 @@ func Test_ResponseWriter(t *testing.T) {
Convey("Write string to response writer", t, func() {
resp := httptest.NewRecorder()
rw := NewResponseWriter("GET", resp)
rw.Write([]byte("Hello world"))
_, _ = rw.Write([]byte("Hello world"))

So(resp.Code, ShouldEqual, rw.Status())
So(resp.Body.String(), ShouldEqual, "Hello world")
Expand All @@ -80,8 +80,8 @@ func Test_ResponseWriter(t *testing.T) {
Convey("Write strings to response writer", t, func() {
resp := httptest.NewRecorder()
rw := NewResponseWriter("GET", resp)
rw.Write([]byte("Hello world"))
rw.Write([]byte("foo bar bat baz"))
_, _ = rw.Write([]byte("Hello world"))
_, _ = rw.Write([]byte("foo bar bat baz"))

So(resp.Code, ShouldEqual, rw.Status())
So(resp.Body.String(), ShouldEqual, "Hello worldfoo bar bat baz")
Expand Down Expand Up @@ -143,7 +143,7 @@ func Test_ResponseWriter(t *testing.T) {
resp := newCloseNotifyingRecorder()
rw := NewResponseWriter("GET", resp)
closed := false
notifier := rw.(http.CloseNotifier).CloseNotify()
notifier := rw.(http.CloseNotifier).CloseNotify() //nolint
resp.close()
select {
case <-notifier:
Expand Down Expand Up @@ -172,7 +172,7 @@ func Test_ResponseWriter(t *testing.T) {

for i := 0; i < 2; i++ {
time.Sleep(10 * time.Millisecond)
io.WriteString(w, "data: Hello\n\n")
_, _ = io.WriteString(w, "data: Hello\n\n")
f.Flush()
}
})
Expand Down
4 changes: 2 additions & 2 deletions return_handler.go
Expand Up @@ -68,9 +68,9 @@ func defaultReturnHandler() ReturnHandler {
respVal = respVal.Elem()
}
if isByteSlice(respVal) {
resp.Write(respVal.Bytes())
_, _ = resp.Write(respVal.Bytes())
} else {
resp.Write([]byte(respVal.String()))
_, _ = resp.Write([]byte(respVal.String()))
}
}
}
2 changes: 1 addition & 1 deletion router_test.go
Expand Up @@ -321,7 +321,7 @@ func Test_Router_InternalServerError(t *testing.T) {
})
m.InternalServerError(func(rw http.ResponseWriter, err error) {
rw.WriteHeader(500)
rw.Write([]byte(err.Error()))
_, _ = rw.Write([]byte(err.Error()))
})
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
Expand Down
2 changes: 1 addition & 1 deletion static_test.go
Expand Up @@ -69,7 +69,7 @@ func Test_Static(t *testing.T) {
Root = os.TempDir()
f, err := ioutil.TempFile(Root, "static_content")
So(err, ShouldBeNil)
f.WriteString("Expected Content")
_, _ = f.WriteString("Expected Content")
f.Close()

m := New()
Expand Down