etcd_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2014 CoreOS, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package etcdmain
  14. import (
  15. "net/url"
  16. "testing"
  17. "github.com/coreos/etcd/pkg/types"
  18. )
  19. func mustNewURLs(t *testing.T, urls []string) []url.URL {
  20. u, err := types.NewURLs(urls)
  21. if err != nil {
  22. t.Fatalf("unexpected new urls error: %v", err)
  23. }
  24. return u
  25. }
  26. func TestGenClusterString(t *testing.T) {
  27. tests := []struct {
  28. token string
  29. urls []string
  30. wstr string
  31. }{
  32. {
  33. "default", []string{"http://127.0.0.1:4001"},
  34. "default=http://127.0.0.1:4001",
  35. },
  36. {
  37. "node1", []string{"http://0.0.0.0:2379", "http://1.1.1.1:2379"},
  38. "node1=http://0.0.0.0:2379,node1=http://1.1.1.1:2379",
  39. },
  40. }
  41. for i, tt := range tests {
  42. urls := mustNewURLs(t, tt.urls)
  43. str := genClusterString(tt.token, urls)
  44. if str != tt.wstr {
  45. t.Errorf("#%d: cluster = %s, want %s", i, str, tt.wstr)
  46. }
  47. }
  48. }