config_test.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 TestConfigVerify(t *testing.T) {
  18. tests := []struct {
  19. clusterSetting string
  20. shouldError bool
  21. }{
  22. {"", true},
  23. {"node1=http://localhost:7001,node2=http://localhost:7001", true},
  24. {"node1=http://localhost:7001,node2=http://localhost:7002", false},
  25. }
  26. for i, tt := range tests {
  27. cluster := &Cluster{}
  28. cluster.Set(tt.clusterSetting)
  29. cfg := ServerConfig{
  30. Name: "node1",
  31. Cluster: cluster,
  32. }
  33. err := cfg.Verify()
  34. if (err == nil) && tt.shouldError {
  35. t.Errorf("#%d: Got no error where one was expected", i)
  36. }
  37. if (err != nil) && !tt.shouldError {
  38. t.Errorf("#%d: Got unexpected error: %v", i, err)
  39. }
  40. }
  41. }