canonicalize_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. "reflect"
  7. "testing"
  8. )
  9. func TestCanonicalize(t *testing.T) {
  10. tests := []struct {
  11. Input []string
  12. Output []string
  13. }{
  14. {
  15. Input: []string{"http://127.0.0.1/"},
  16. Output: []string{"http://127.0.0.1"},
  17. },
  18. {
  19. Input: []string{"http://127.0.0.1:9200/", "gopher://golang.org/", "http://127.0.0.1:9201"},
  20. Output: []string{"http://127.0.0.1:9200", "http://127.0.0.1:9201"},
  21. },
  22. {
  23. Input: []string{"http://user:secret@127.0.0.1/path?query=1#fragment"},
  24. Output: []string{"http://user:secret@127.0.0.1"},
  25. },
  26. {
  27. Input: []string{"https://somewhere.on.mars:9999/path?query=1#fragment"},
  28. Output: []string{"https://somewhere.on.mars:9999"},
  29. },
  30. }
  31. for _, test := range tests {
  32. got := canonicalize(test.Input...)
  33. if !reflect.DeepEqual(got, test.Output) {
  34. t.Errorf("expected %v; got: %v", test.Output, got)
  35. }
  36. }
  37. }