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