Skip to content

Commit 9342591

Browse files
committed
Tests: Add typed api serialisation test for inlined addional properties
1 parent 75c1798 commit 9342591

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

elasticsearch_integration_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package elasticsearch_test
2222

2323
import (
24+
"bytes"
2425
"context"
2526
"crypto/tls"
2627
"encoding/json"
@@ -29,6 +30,7 @@ import (
2930
"github.com/elastic/go-elasticsearch/v8/typedapi/indices/create"
3031
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
3132
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
33+
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
3234
"log"
3335
"net"
3436
"net/http"
@@ -495,4 +497,26 @@ func TestTypedClient(t *testing.T) {
495497
t.Fatalf("unexpected string in Query.Term.Value, expected kimchy, got: %s", searchRequest.Query.Term["user.id"].Value.(string))
496498
}
497499
})
500+
501+
t.Run("Sort serialisation", func(t *testing.T) {
502+
qry := search.NewRequestBuilder().Sort(
503+
types.NewSortBuilder().Sort(
504+
[]types.SortCombinations{
505+
types.NewSortCombinationsBuilder().
506+
Field("@timestamp").
507+
SortOptions(types.NewSortOptionsBuilder().
508+
SortOptions(map[types.Field]*types.FieldSortBuilder{
509+
"@timestamp": types.NewFieldSortBuilder().Format("strict_date_optional_time_nanos").Order(sortorder.Asc),
510+
})).Build(),
511+
})).Build()
512+
513+
data, err := json.Marshal(qry)
514+
if err != nil {
515+
t.Fatal(err)
516+
}
517+
518+
if bytes.Compare(data, []byte(`{"sort":[{"@timestamp":{"format":"strict_date_optional_time_nanos","order":"asc"}}]}`)) != 0 {
519+
t.Fatalf("invalid sort serialisation, got: %s", data)
520+
}
521+
})
498522
}

0 commit comments

Comments
 (0)