etcd_config_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // Copyright 2018 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 rpcpb
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/coreos/etcd/embed"
  19. "github.com/coreos/etcd/pkg/types"
  20. )
  21. func TestEtcd(t *testing.T) {
  22. e := &Etcd{
  23. Name: "s1",
  24. DataDir: "/tmp/etcd-functionl-1/etcd.data",
  25. WALDir: "/tmp/etcd-functionl-1/etcd.data/member/wal",
  26. HeartbeatIntervalMs: 100,
  27. ElectionTimeoutMs: 1000,
  28. ListenClientURLs: []string{"https://127.0.0.1:1379"},
  29. AdvertiseClientURLs: []string{"https://127.0.0.1:13790"},
  30. ClientAutoTLS: true,
  31. ClientCertAuth: false,
  32. ClientCertFile: "",
  33. ClientKeyFile: "",
  34. ClientTrustedCAFile: "",
  35. ListenPeerURLs: []string{"https://127.0.0.1:1380"},
  36. AdvertisePeerURLs: []string{"https://127.0.0.1:13800"},
  37. PeerAutoTLS: true,
  38. PeerClientCertAuth: false,
  39. PeerCertFile: "",
  40. PeerKeyFile: "",
  41. PeerTrustedCAFile: "",
  42. InitialCluster: "s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800",
  43. InitialClusterState: "new",
  44. InitialClusterToken: "tkn",
  45. SnapshotCount: 10000,
  46. QuotaBackendBytes: 10740000000,
  47. PreVote: true,
  48. InitialCorruptCheck: true,
  49. Logger: "zap",
  50. LogOutputs: []string{"/tmp/etcd-functional-1/etcd.log"},
  51. Debug: true,
  52. }
  53. exps := []string{
  54. "--name=s1",
  55. "--data-dir=/tmp/etcd-functionl-1/etcd.data",
  56. "--wal-dir=/tmp/etcd-functionl-1/etcd.data/member/wal",
  57. "--heartbeat-interval=100",
  58. "--election-timeout=1000",
  59. "--listen-client-urls=https://127.0.0.1:1379",
  60. "--advertise-client-urls=https://127.0.0.1:13790",
  61. "--auto-tls=true",
  62. "--client-cert-auth=false",
  63. "--listen-peer-urls=https://127.0.0.1:1380",
  64. "--initial-advertise-peer-urls=https://127.0.0.1:13800",
  65. "--peer-auto-tls=true",
  66. "--peer-client-cert-auth=false",
  67. "--initial-cluster=s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800",
  68. "--initial-cluster-state=new",
  69. "--initial-cluster-token=tkn",
  70. "--snapshot-count=10000",
  71. "--quota-backend-bytes=10740000000",
  72. "--pre-vote=true",
  73. "--experimental-initial-corrupt-check=true",
  74. "--logger=zap",
  75. "--log-outputs=/tmp/etcd-functional-1/etcd.log",
  76. "--debug=true",
  77. }
  78. fs := e.Flags()
  79. if !reflect.DeepEqual(exps, fs) {
  80. t.Fatalf("expected %q, got %q", exps, fs)
  81. }
  82. var err error
  83. var lcURLs types.URLs
  84. lcURLs, err = types.NewURLs([]string{"https://127.0.0.1:1379"})
  85. if err != nil {
  86. t.Fatal(err)
  87. }
  88. var acURLs types.URLs
  89. acURLs, err = types.NewURLs([]string{"https://127.0.0.1:13790"})
  90. if err != nil {
  91. t.Fatal(err)
  92. }
  93. var lpURLs types.URLs
  94. lpURLs, err = types.NewURLs([]string{"https://127.0.0.1:1380"})
  95. if err != nil {
  96. t.Fatal(err)
  97. }
  98. var apURLs types.URLs
  99. apURLs, err = types.NewURLs([]string{"https://127.0.0.1:13800"})
  100. if err != nil {
  101. t.Fatal(err)
  102. }
  103. expc := embed.NewConfig()
  104. expc.Name = "s1"
  105. expc.Dir = "/tmp/etcd-functionl-1/etcd.data"
  106. expc.WalDir = "/tmp/etcd-functionl-1/etcd.data/member/wal"
  107. expc.TickMs = 100
  108. expc.ElectionMs = 1000
  109. expc.LCUrls = lcURLs
  110. expc.ACUrls = acURLs
  111. expc.ClientAutoTLS = true
  112. expc.LPUrls = lpURLs
  113. expc.APUrls = apURLs
  114. expc.PeerAutoTLS = true
  115. expc.InitialCluster = "s1=https://127.0.0.1:13800,s2=https://127.0.0.1:23800,s3=https://127.0.0.1:33800"
  116. expc.ClusterState = "new"
  117. expc.InitialClusterToken = "tkn"
  118. expc.SnapCount = 10000
  119. expc.QuotaBackendBytes = 10740000000
  120. expc.PreVote = true
  121. expc.ExperimentalInitialCorruptCheck = true
  122. expc.Logger = "zap"
  123. expc.LogOutputs = []string{"/tmp/etcd-functional-1/etcd.log"}
  124. expc.Debug = true
  125. cfg, err := e.EmbedConfig()
  126. if err != nil {
  127. t.Fatal(err)
  128. }
  129. if !reflect.DeepEqual(expc, cfg) {
  130. t.Fatalf("expected %+v, got %+v", expc, cfg)
  131. }
  132. }