Merge 7cfa743cd0
into 167d78773c
This commit is contained in:
commit
79f8c3e4c8
@ -1,4 +1,4 @@
|
|||||||
package: github.com/OwnLocal/goes
|
package: github.com/arhitiron/goes
|
||||||
import: []
|
import: []
|
||||||
testImport:
|
testImport:
|
||||||
- package: github.com/go-check/check
|
- package: github.com/go-check/check
|
||||||
|
5
goes.go
5
goes.go
@ -353,8 +353,9 @@ func (req *Request) Run() (*Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if req.method != "HEAD" {
|
if req.method != "HEAD" {
|
||||||
err = json.Unmarshal(body, &esResp)
|
dec := json.NewDecoder(bytes.NewReader(body))
|
||||||
if err != nil {
|
dec.UseNumber()
|
||||||
|
if err := dec.Decode(&esResp); err != nil {
|
||||||
return esResp, err
|
return esResp, err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(body, &esResp.Raw)
|
err = json.Unmarshal(body, &esResp.Raw)
|
||||||
|
49
goes_test.go
49
goes_test.go
@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/go-check/check"
|
. "github.com/go-check/check"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -21,7 +22,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Hook up gocheck into the gotest runner.
|
// Hook up gocheck into the gotest runner.
|
||||||
func Test(t *testing.T) { TestingT(t) }
|
func Test(t *testing.T) {
|
||||||
|
TestingT(t)
|
||||||
|
}
|
||||||
|
|
||||||
type GoesTestSuite struct{}
|
type GoesTestSuite struct{}
|
||||||
|
|
||||||
@ -735,6 +738,13 @@ func (s *GoesTestSuite) TestSearch(c *C) {
|
|||||||
}
|
}
|
||||||
response, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})
|
response, err := conn.Search(query, []string{indexName}, []string{docType}, url.Values{})
|
||||||
|
|
||||||
|
|
||||||
|
//Type of response.Hits.MaxScore is json.Number, and DeepEquals will return false,
|
||||||
|
// so we need to change it manualy
|
||||||
|
jsonNumberMaxScore, _ := response.Hits.MaxScore.(json.Number)
|
||||||
|
maxScore, _ := jsonNumberMaxScore.Float64()
|
||||||
|
response.Hits.MaxScore = maxScore
|
||||||
|
|
||||||
expectedHits := Hits{
|
expectedHits := Hits{
|
||||||
Total: 1,
|
Total: 1,
|
||||||
MaxScore: 1.0,
|
MaxScore: 1.0,
|
||||||
@ -825,9 +835,12 @@ func (s *GoesTestSuite) TestIndexStatus(c *C) {
|
|||||||
expectedShards := Shard{Total: 2, Successful: 1, Failed: 0}
|
expectedShards := Shard{Total: 2, Successful: 1, Failed: 0}
|
||||||
c.Assert(response.Shards, Equals, expectedShards)
|
c.Assert(response.Shards, Equals, expectedShards)
|
||||||
|
|
||||||
primarySizeInBytes := response.Indices[indexName].Index["primary_size_in_bytes"].(float64)
|
jsonPrimarySizeInBytes, _ := response.Indices[indexName].Index["primary_size_in_bytes"].(json.Number)
|
||||||
sizeInBytes := response.Indices[indexName].Index["size_in_bytes"].(float64)
|
primarySizeInBytes, _ := jsonPrimarySizeInBytes.Float64()
|
||||||
refreshTotal := response.Indices[indexName].Refresh["total"].(float64)
|
jsonSizeInBytes, _ := response.Indices[indexName].Index["size_in_bytes"].(json.Number)
|
||||||
|
sizeInBytes, _ := jsonSizeInBytes.Float64()
|
||||||
|
jsonRefreshTotal, _ := response.Indices[indexName].Refresh["total"].(json.Number)
|
||||||
|
refreshTotal, _ := jsonRefreshTotal.Float64()
|
||||||
|
|
||||||
c.Assert(primarySizeInBytes > 0, Equals, true)
|
c.Assert(primarySizeInBytes > 0, Equals, true)
|
||||||
c.Assert(sizeInBytes > 0, Equals, true)
|
c.Assert(sizeInBytes > 0, Equals, true)
|
||||||
@ -1066,18 +1079,30 @@ func (s *GoesTestSuite) TestAggregations(c *C) {
|
|||||||
c.Assert(user.Buckets()[1].Key(), Equals, "foo")
|
c.Assert(user.Buckets()[1].Key(), Equals, "foo")
|
||||||
|
|
||||||
barAge := user.Buckets()[0].Aggregation("age")
|
barAge := user.Buckets()[0].Aggregation("age")
|
||||||
c.Assert(barAge["count"], Equals, 1.0)
|
jCount, _ := barAge["count"].(json.Number)
|
||||||
c.Assert(barAge["sum"], Equals, 30.0)
|
countInt64, _ := jCount.Int64()
|
||||||
|
c.Assert(countInt64, Equals, int64(1))
|
||||||
|
jSum, _ := barAge["sum"].(json.Number)
|
||||||
|
sumFloat64, _ := jSum.Float64()
|
||||||
|
c.Assert(sumFloat64, Equals, 30.0)
|
||||||
|
|
||||||
fooAge := user.Buckets()[1].Aggregation("age")
|
fooAge := user.Buckets()[1].Aggregation("age")
|
||||||
c.Assert(fooAge["count"], Equals, 1.0)
|
jCount, _ = fooAge["count"].(json.Number)
|
||||||
c.Assert(fooAge["sum"], Equals, 25.0)
|
countInt64, _ = jCount.Int64()
|
||||||
|
c.Assert(countInt64, Equals, int64(1))
|
||||||
|
jSum, _ = fooAge["sum"].(json.Number)
|
||||||
|
sumFloat64, _ = jSum.Float64()
|
||||||
|
c.Assert(sumFloat64, Equals, 25.0)
|
||||||
|
|
||||||
age, ok := resp.Aggregations["age"]
|
age, ok := resp.Aggregations["age"]
|
||||||
c.Assert(ok, Equals, true)
|
c.Assert(ok, Equals, true)
|
||||||
|
|
||||||
c.Assert(age["count"], Equals, 2.0)
|
jCount, _ = age["count"].(json.Number)
|
||||||
c.Assert(age["sum"], Equals, 25.0+30.0)
|
countInt64, _ = jCount.Int64()
|
||||||
|
c.Assert(countInt64, Equals, int64(2))
|
||||||
|
jSum, _ = age["sum"].(json.Number)
|
||||||
|
sumFloat64, _ = jSum.Float64()
|
||||||
|
c.Assert(sumFloat64, Equals, 25.0 + 30.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GoesTestSuite) TestPutMapping(c *C) {
|
func (s *GoesTestSuite) TestPutMapping(c *C) {
|
||||||
@ -1210,7 +1235,9 @@ func (s *GoesTestSuite) TestUpdate(c *C) {
|
|||||||
|
|
||||||
response, err = conn.Get(indexName, docType, docId, url.Values{})
|
response, err = conn.Get(indexName, docType, docId, url.Values{})
|
||||||
c.Assert(err, Equals, nil)
|
c.Assert(err, Equals, nil)
|
||||||
c.Assert(response.Source["counter"], Equals, float64(6))
|
jsonCounter, _ := response.Source["counter"].(json.Number)
|
||||||
|
counter, _ := jsonCounter.Float64()
|
||||||
|
c.Assert(counter, Equals, float64(6))
|
||||||
c.Assert(response.Source["user"], Equals, "foo")
|
c.Assert(response.Source["user"], Equals, "foo")
|
||||||
c.Assert(response.Source["message"], Equals, "bar")
|
c.Assert(response.Source["message"], Equals, "bar")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user