search_aggs_geo_bounds_test.go 1018 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright 2012-2015 Oliver Eilhard. All rights reserved.
  2. // Use of this source code is governed by a MIT-license.
  3. // See http://olivere.mit-license.org/license.txt for details.
  4. package elastic
  5. import (
  6. "encoding/json"
  7. "testing"
  8. )
  9. func TestGeoBoundsAggregation(t *testing.T) {
  10. agg := NewGeoBoundsAggregation().Field("location")
  11. data, err := json.Marshal(agg.Source())
  12. if err != nil {
  13. t.Fatalf("marshaling to JSON failed: %v", err)
  14. }
  15. got := string(data)
  16. expected := `{"geo_bounds":{"field":"location"}}`
  17. if got != expected {
  18. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  19. }
  20. }
  21. func TestGeoBoundsAggregationWithWrapLongitude(t *testing.T) {
  22. agg := NewGeoBoundsAggregation().Field("location").WrapLongitude(true)
  23. data, err := json.Marshal(agg.Source())
  24. if err != nil {
  25. t.Fatalf("marshaling to JSON failed: %v", err)
  26. }
  27. got := string(data)
  28. expected := `{"geo_bounds":{"field":"location","wrap_longitude":true}}`
  29. if got != expected {
  30. t.Errorf("expected\n%s\n,got:\n%s", expected, got)
  31. }
  32. }