bulk_delete_request_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. "testing"
  7. )
  8. func TestBulkDeleteRequestSerialization(t *testing.T) {
  9. tests := []struct {
  10. Request BulkableRequest
  11. Expected []string
  12. }{
  13. // #0
  14. {
  15. Request: NewBulkDeleteRequest().Index("index1").Type("tweet").Id("1"),
  16. Expected: []string{
  17. `{"delete":{"_id":"1","_index":"index1","_type":"tweet"}}`,
  18. },
  19. },
  20. }
  21. for i, test := range tests {
  22. lines, err := test.Request.Source()
  23. if err != nil {
  24. t.Fatalf("case #%d: expected no error, got: %v", i, err)
  25. }
  26. if lines == nil {
  27. t.Fatalf("case #%d: expected lines, got nil", i)
  28. }
  29. if len(lines) != len(test.Expected) {
  30. t.Fatalf("case #%d: expected %d lines, got %d", i, len(test.Expected), len(lines))
  31. }
  32. for j, line := range lines {
  33. if line != test.Expected[j] {
  34. t.Errorf("case #%d: expected line #%d to be %s, got: %s", i, j, test.Expected[j], line)
  35. }
  36. }
  37. }
  38. }