etcd_config_test.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2016 The etcd Authors
  2. //
  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. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package e2e
  15. import (
  16. "fmt"
  17. "io/ioutil"
  18. "os"
  19. "strings"
  20. "testing"
  21. "github.com/coreos/etcd/pkg/expect"
  22. )
  23. const exampleConfigFile = "../etcd.conf.yml.sample"
  24. func TestEtcdExampleConfig(t *testing.T) {
  25. proc, err := spawnCmd([]string{binDir + "/etcd", "--config-file", exampleConfigFile})
  26. if err != nil {
  27. t.Fatal(err)
  28. }
  29. if err = waitReadyExpectProc(proc, false); err != nil {
  30. t.Fatal(err)
  31. }
  32. if err = proc.Stop(); err != nil {
  33. t.Fatal(err)
  34. }
  35. }
  36. func TestEtcdMultiPeer(t *testing.T) {
  37. peers, tmpdirs := make([]string, 3), make([]string, 3)
  38. for i := range peers {
  39. peers[i] = fmt.Sprintf("e%d=http://127.0.0.1:%d", i, etcdProcessBasePort+i)
  40. d, err := ioutil.TempDir("", fmt.Sprintf("e%d.etcd", i))
  41. if err != nil {
  42. t.Fatal(err)
  43. }
  44. tmpdirs[i] = d
  45. }
  46. ic := strings.Join(peers, ",")
  47. procs := make([]*expect.ExpectProcess, len(peers))
  48. defer func() {
  49. for i := range procs {
  50. if procs[i] != nil {
  51. procs[i].Stop()
  52. }
  53. os.RemoveAll(tmpdirs[i])
  54. }
  55. }()
  56. for i := range procs {
  57. args := []string{
  58. binDir + "/etcd",
  59. "--name", fmt.Sprintf("e%d", i),
  60. "--listen-client-urls", "http://0.0.0.0:0",
  61. "--data-dir", tmpdirs[i],
  62. "--advertise-client-urls", "http://0.0.0.0:0",
  63. "--listen-peer-urls", fmt.Sprintf("http://127.0.0.1:%d,http://127.0.0.1:%d", etcdProcessBasePort+i, etcdProcessBasePort+len(peers)+i),
  64. "--initial-advertise-peer-urls", fmt.Sprintf("http://127.0.0.1:%d", etcdProcessBasePort+i),
  65. "--initial-cluster", ic,
  66. }
  67. p, err := spawnCmd(args)
  68. if err != nil {
  69. t.Fatal(err)
  70. }
  71. procs[i] = p
  72. }
  73. for _, p := range procs {
  74. if err := waitReadyExpectProc(p, false); err != nil {
  75. t.Fatal(err)
  76. }
  77. }
  78. }