config_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 etcdserver
  14. import (
  15. "testing"
  16. )
  17. func TestBootstrapConfigVerify(t *testing.T) {
  18. tests := []struct {
  19. clusterSetting string
  20. clst ClusterState
  21. disc string
  22. shouldError bool
  23. }{
  24. {"", ClusterStateValueNew, "", true},
  25. {"", "", "http://discovery", true},
  26. {
  27. "node1=http://localhost:7001,node2=http://localhost:7001",
  28. ClusterStateValueNew, "", true,
  29. },
  30. {
  31. "node1=http://localhost:7001,node2=http://localhost:7002",
  32. ClusterStateValueNew, "", false,
  33. },
  34. {
  35. "node1=http://localhost:7001",
  36. "", "http://discovery", false,
  37. },
  38. }
  39. for i, tt := range tests {
  40. cluster := &Cluster{}
  41. err := cluster.SetMembersFromString(tt.clusterSetting)
  42. if err != nil && tt.shouldError {
  43. continue
  44. }
  45. cfg := ServerConfig{
  46. Name: "node1",
  47. DiscoveryURL: tt.disc,
  48. Cluster: cluster,
  49. ClusterState: tt.clst,
  50. }
  51. err = cfg.VerifyBootstrapConfig()
  52. if (err == nil) && tt.shouldError {
  53. t.Errorf("%#v", *cluster)
  54. t.Errorf("#%d: Got no error where one was expected", i)
  55. }
  56. if (err != nil) && !tt.shouldError {
  57. t.Errorf("#%d: Got unexpected error: %v", i, err)
  58. }
  59. }
  60. }