Skip to content

Commit

Permalink
test: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 10, 2023
1 parent 16bd946 commit 54087dd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 6 deletions.
23 changes: 23 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
4 changes: 4 additions & 0 deletions elton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
2 changes: 0 additions & 2 deletions middleware/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"net/http/httptest"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/vicanso/elton"
Expand All @@ -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))]
}
Expand Down
3 changes: 2 additions & 1 deletion multipart_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
14 changes: 14 additions & 0 deletions multipart_form_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

0 comments on commit 54087dd

Please sign in to comment.