1
0

version_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2016 fatedier, fatedier@gmail.com
  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 version
  15. import (
  16. "fmt"
  17. "strconv"
  18. "strings"
  19. "testing"
  20. "github.com/stretchr/testify/assert"
  21. )
  22. func TestFull(t *testing.T) {
  23. assert := assert.New(t)
  24. version := Full()
  25. arr := strings.Split(version, ".")
  26. assert.Equal(3, len(arr))
  27. proto, err := strconv.ParseInt(arr[0], 10, 64)
  28. assert.NoError(err)
  29. assert.True(proto >= 0)
  30. major, err := strconv.ParseInt(arr[1], 10, 64)
  31. assert.NoError(err)
  32. assert.True(major >= 0)
  33. minor, err := strconv.ParseInt(arr[2], 10, 64)
  34. assert.NoError(err)
  35. assert.True(minor >= 0)
  36. }
  37. func TestVersion(t *testing.T) {
  38. assert := assert.New(t)
  39. proto := Proto(Full())
  40. major := Major(Full())
  41. minor := Minor(Full())
  42. parseVerion := fmt.Sprintf("%d.%d.%d", proto, major, minor)
  43. version := Full()
  44. assert.Equal(parseVerion, version)
  45. }
  46. func TestCompact(t *testing.T) {
  47. assert := assert.New(t)
  48. ok, _ := Compat("0.9.0")
  49. assert.False(ok)
  50. ok, _ = Compat("10.0.0")
  51. assert.True(ok)
  52. ok, _ = Compat("0.10.0")
  53. assert.True(ok)
  54. }