cluster_util_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2015 CoreOS, Inc.
  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 etcdserver
  15. import (
  16. "reflect"
  17. "testing"
  18. "github.com/coreos/etcd/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
  19. )
  20. func TestDecideClusterVersion(t *testing.T) {
  21. tests := []struct {
  22. vers map[string]string
  23. wdver *semver.Version
  24. }{
  25. {
  26. map[string]string{"a": "2.0.0"},
  27. semver.Must(semver.NewVersion("2.0.0")),
  28. },
  29. // unknow
  30. {
  31. map[string]string{"a": ""},
  32. nil,
  33. },
  34. {
  35. map[string]string{"a": "2.0.0", "b": "2.1.0", "c": "2.1.0"},
  36. semver.Must(semver.NewVersion("2.0.0")),
  37. },
  38. {
  39. map[string]string{"a": "2.1.0", "b": "2.1.0", "c": "2.1.0"},
  40. semver.Must(semver.NewVersion("2.1.0")),
  41. },
  42. {
  43. map[string]string{"a": "", "b": "2.1.0", "c": "2.1.0"},
  44. nil,
  45. },
  46. }
  47. for i, tt := range tests {
  48. dver := decideClusterVersion(tt.vers)
  49. if !reflect.DeepEqual(dver, tt.wdver) {
  50. t.Errorf("#%d: ver = %+v, want %+v", i, dver, tt.wdver)
  51. }
  52. }
  53. }