diff --git a/context_test.go b/context_test.go index 05f4994..f420a3c 100644 --- a/context_test.go +++ b/context_test.go @@ -823,3 +823,26 @@ func TestPipe(t *testing.T) { assert.Equal(int64(len(data)), written) assert.Equal(data, resp.Body.Bytes()) } + +func TestContextGetTrace(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest("GET", "/", nil) + assert.Nil(err) + c := NewContext(nil, req) + assert.NotNil(c.GetTrace()) +} + +func TestContextIsContext(t *testing.T) { + assert := assert.New(t) + req, err := http.NewRequest("GET", "/", nil) + assert.Nil(err) + c := NewContext(nil, req) + + _, ok := c.Deadline() + assert.False(ok) + + assert.Nil(c.Done()) + assert.Nil(c.Err()) + + assert.Nil(c.Value("abc")) +} diff --git a/elton_test.go b/elton_test.go index 3d591b2..6ec1fda 100644 --- a/elton_test.go +++ b/elton_test.go @@ -397,6 +397,10 @@ func TestOnError(t *testing.T) { assert.Equal(customErr, err) }) e.EmitError(c, customErr) + req, err := http.NewRequest("GET", "/", nil) + assert.Nil(err) + + e.emitError(httptest.NewRecorder(), req, customErr) } func TestOnTrace(t *testing.T) { diff --git a/go.mod b/go.mod index 580966f..019dd37 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/tidwall/match v1.1.1 // indirect - github.com/tidwall/pretty v1.2.1 // indirect + github.com/tidwall/pretty v1.2.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index e714564..0a6d402 100644 --- a/go.sum +++ b/go.sum @@ -18,9 +18,8 @@ github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= +github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= -github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/vicanso/hes v0.6.1 h1:BRGUDhV2sJYMieJf4dgxFXjvuhDgUWBsINELcti0Z8M= github.com/vicanso/hes v0.6.1/go.mod h1:awwBbvcDTk8APxRmiV7Hxrir89/iCxgB6RMeLc5toh0= github.com/vicanso/intranet-ip v0.1.0 h1:UeoxilO2VDIkeZZxmu6aT+f5o79mfGdsSdwoEv75nYo= diff --git a/middleware/compress_test.go b/middleware/compress_test.go index e7503fb..f0455c8 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -29,7 +29,6 @@ import ( "net/http/httptest" "sync/atomic" "testing" - "time" "github.com/stretchr/testify/assert" "github.com/vicanso/elton" @@ -54,7 +53,6 @@ func (t *testCompressor) Pipe(c *elton.Context) error { // randomString get random string func randomString(n int) string { b := make([]rune, n) - rand.Seed(time.Now().UnixNano()) for i := range b { b[i] = letterRunes[rand.Intn(len(letterRunes))] } diff --git a/multipart_form.go b/multipart_form.go index 2b35ed0..191cf63 100644 --- a/multipart_form.go +++ b/multipart_form.go @@ -36,7 +36,8 @@ type multipartForm struct { contentType string } -// NewMultipartForm returns a new multipart form +// NewMultipartForm returns a new multipart form, +// the form data will be saved as tmp file for less memory. func NewMultipartForm() *multipartForm { return &multipartForm{} } diff --git a/multipart_form_test.go b/multipart_form_test.go index 8caf41d..1196ec8 100644 --- a/multipart_form_test.go +++ b/multipart_form_test.go @@ -44,6 +44,10 @@ func TestMultipartForm(t *testing.T) { err = form.AddFile("file", "test.txt", bytes.NewBufferString("Hello world!")) assert.Nil(err) + err = form.AddFile("source", "./multipart_form_test.go") + assert.Nil(err) + + assert.True(strings.HasPrefix(form.ContentType(), "multipart/form-data; boundary=")) r, err := form.Reader() assert.Nil(err) buf, err := io.ReadAll(r) @@ -54,3 +58,13 @@ func TestMultipartForm(t *testing.T) { assert.True(strings.Contains(str, `Content-Type: application/octet-stream`)) assert.True(strings.Contains(str, `Content-Disposition: form-data; name="a"`)) } + +func TestTestMultipartFormDestroy(t *testing.T) { + assert := assert.New(t) + form := NewMultipartForm() + err := form.AddField("a", "1") + assert.Nil(err) + + err = form.Destroy() + assert.Nil(err) +}