cluster_util_test.go 1.8 KB

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