Skip to content

Commit

Permalink
chore: update modules
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Feb 29, 2020
1 parent 39646cf commit dc20b48
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sudo: required
go:
- "1.12"
- "1.13"
- "1.14"
- master

script:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/vicanso/elton-json-picker
go 1.12

require (
github.com/stretchr/testify v1.4.0
github.com/vicanso/elton v0.2.3
github.com/stretchr/testify v1.5.1
github.com/vicanso/elton v0.3.0
github.com/vicanso/superjson v0.1.0
)
8 changes: 5 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4d
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tidwall/gjson v1.3.5 h1:2oW9FBNu8qt9jy5URgrzsVx/T/KSn3qn/smJQ0crlDQ=
github.com/tidwall/gjson v1.3.5/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/vicanso/elton v0.2.3 h1:XQskGFtw/hhtNXRU7dLX0OFcpG64pK4PMXh9CVjHVbA=
github.com/vicanso/elton v0.2.3/go.mod h1:QFZ+Un4LLBANtl0mExkqLD4uqw3JLA2ZCWUHaCsHOUg=
github.com/vicanso/elton v0.3.0 h1:3Ap/baOup8XpdpONZtAylXYUl7GNlkPIBUxZZDdEcTk=
github.com/vicanso/elton v0.3.0/go.mod h1:QFZ+Un4LLBANtl0mExkqLD4uqw3JLA2ZCWUHaCsHOUg=
github.com/vicanso/hes v0.2.1 h1:jRFEADmiQ30koVY/sKwlkhyXM5B3QbVVizLqrjNJgPw=
github.com/vicanso/hes v0.2.1/go.mod h1:QcxOFmFfBQMhASTaLgnFayXYCgevdSeBVprt+o+3eKo=
github.com/vicanso/intranet-ip v0.0.1 h1:cYS+mExFsKqewWSuHtFwAqw/CO66GsheB/P1BPmSTx0=
Expand Down
66 changes: 35 additions & 31 deletions json_picker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,51 +55,55 @@ func TestJSONPicker(t *testing.T) {
})

t.Run("pick", func(t *testing.T) {
req := httptest.NewRequest("GET", "/users/me?fields=i,f,s,b,arr,m,null,xx", nil)
resp := httptest.NewRecorder()
c := elton.NewContext(resp, req)
m := map[string]interface{}{
"_x": "abcd",
"i": 1,
"f": 1.12,
"s": "\"abc",
"b": false,
"arr": []interface{}{
1,
"2",
true,
},
"m": map[string]interface{}{
"a": 1,
"b": "2",
"c": false,
},
"null": nil,
}
buf, _ := json.Marshal(m)
c.BodyBuffer = bytes.NewBuffer(buf)
c.StatusCode = 200
c.Next = func() error {
return nil
genContext := func(url string) *elton.Context {

req := httptest.NewRequest("GET", url, nil)
resp := httptest.NewRecorder()
c := elton.NewContext(resp, req)
m := map[string]interface{}{
"_x": "abcd",
"i": 1,
"f": 1.12,
"s": "\"abc",
"b": false,
"arr": []interface{}{
1,
"2",
true,
},
"m": map[string]interface{}{
"a": 1,
"b": "2",
"c": false,
},
"null": nil,
}
buf, _ := json.Marshal(m)
c.BodyBuffer = bytes.NewBuffer(buf)
c.StatusCode = 200
c.Next = func() error {
return nil
}
c.SetHeader(elton.HeaderContentType, elton.MIMEApplicationJSON)
return c
}
c.SetHeader(elton.HeaderContentType, elton.MIMEApplicationJSON)
fn := New(Config{
Field: "fields",
})
t.Run("pick fields", func(t *testing.T) {
c := genContext("/users/me?fields=i,f,s,b,arr,m,null,xx")
assert := assert.New(t)
err := fn(c)
assert.Nil(err, "json picker fail")
assert.Equal(c.BodyBuffer.String(), `{"arr":[1,"2",true],"b":false,"f":1.12,"i":1,"m":{"a":1,"b":"2","c":false},"s":"\"abc"}`)
assert.Equal(`{"arr":[1,"2",true],"b":false,"f":1.12,"i":1,"m":{"a":1,"b":"2","c":false},"s":"\"abc"}`, c.BodyBuffer.String())
})

t.Run("omit fields", func(t *testing.T) {
assert := assert.New(t)
req := httptest.NewRequest("GET", "/users/me?fields=-x", nil)
c.Request = req
c := genContext("/users/me?fields=-_x")
err := fn(c)
assert.Nil(err, "omit picker fail")
assert.Equal(c.BodyBuffer.String(), `{"arr":[1,"2",true],"b":false,"f":1.12,"i":1,"m":{"a":1,"b":"2","c":false},"s":"\"abc"}`)
assert.Equal(`{"arr":[1,"2",true],"b":false,"f":1.12,"i":1,"m":{"a":1,"b":"2","c":false},"s":"\"abc"}`, c.BodyBuffer.String())
})
})
}
Expand Down

0 comments on commit dc20b48

Please sign in to comment.