config_test.go 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2012-present 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 config
  5. import "testing"
  6. func TestParse(t *testing.T) {
  7. urls := "http://user:pwd@elastic:19220/store-blobs?shards=5&replicas=2&sniff=true&healthcheck=false&errorlog=elastic.error.log&infolog=elastic.info.log&tracelog=elastic.trace.log"
  8. cfg, err := Parse(urls)
  9. if err != nil {
  10. t.Fatal(err)
  11. }
  12. if want, got := "http://elastic:19220", cfg.URL; want != got {
  13. t.Fatalf("expected URL = %q, got %q", want, got)
  14. }
  15. if want, got := "store-blobs", cfg.Index; want != got {
  16. t.Fatalf("expected Index = %q, got %q", want, got)
  17. }
  18. if want, got := "user", cfg.Username; want != got {
  19. t.Fatalf("expected Username = %q, got %q", want, got)
  20. }
  21. if want, got := "pwd", cfg.Password; want != got {
  22. t.Fatalf("expected Password = %q, got %q", want, got)
  23. }
  24. if want, got := 5, cfg.Shards; want != got {
  25. t.Fatalf("expected Shards = %v, got %v", want, got)
  26. }
  27. if want, got := 2, cfg.Replicas; want != got {
  28. t.Fatalf("expected Replicas = %v, got %v", want, got)
  29. }
  30. if want, got := true, *cfg.Sniff; want != got {
  31. t.Fatalf("expected Sniff = %v, got %v", want, got)
  32. }
  33. if want, got := false, *cfg.Healthcheck; want != got {
  34. t.Fatalf("expected Healthcheck = %v, got %v", want, got)
  35. }
  36. if want, got := "elastic.error.log", cfg.Errorlog; want != got {
  37. t.Fatalf("expected Errorlog = %q, got %q", want, got)
  38. }
  39. if want, got := "elastic.info.log", cfg.Infolog; want != got {
  40. t.Fatalf("expected Infolog = %q, got %q", want, got)
  41. }
  42. if want, got := "elastic.trace.log", cfg.Tracelog; want != got {
  43. t.Fatalf("expected Tracelog = %q, got %q", want, got)
  44. }
  45. }
  46. func TestParseDoesNotFailWithoutIndexName(t *testing.T) {
  47. urls := "http://user:pwd@elastic:19220/?shards=5&replicas=2&sniff=true&errorlog=elastic.error.log&infolog=elastic.info.log&tracelog=elastic.trace.log"
  48. cfg, err := Parse(urls)
  49. if err != nil {
  50. t.Fatal(err)
  51. }
  52. if want, got := "http://elastic:19220", cfg.URL; want != got {
  53. t.Fatalf("expected URL = %q, got %q", want, got)
  54. }
  55. if want, got := "", cfg.Index; want != got {
  56. t.Fatalf("expected Index = %q, got %q", want, got)
  57. }
  58. }
  59. func TestParseTrimsIndexName(t *testing.T) {
  60. urls := "http://user:pwd@elastic:19220/store-blobs/?sniff=true"
  61. cfg, err := Parse(urls)
  62. if err != nil {
  63. t.Fatal(err)
  64. }
  65. if want, got := "http://elastic:19220", cfg.URL; want != got {
  66. t.Fatalf("expected URL = %q, got %q", want, got)
  67. }
  68. if want, got := "store-blobs", cfg.Index; want != got {
  69. t.Fatalf("expected Index = %q, got %q", want, got)
  70. }
  71. }