github.com/rajatvaryani/mattermost-server@v5.11.1+incompatible/model/version_test.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package model 5 6 import ( 7 "fmt" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 ) 12 13 func TestSplitVersion(t *testing.T) { 14 major1, minor1, patch1 := SplitVersion("junk") 15 require.EqualValues(t, 0, major1) 16 require.EqualValues(t, 0, minor1) 17 require.EqualValues(t, 0, patch1) 18 19 major2, minor2, patch2 := SplitVersion("1.2.3") 20 require.EqualValues(t, 1, major2) 21 require.EqualValues(t, 2, minor2) 22 require.EqualValues(t, 3, patch2) 23 24 major3, minor3, patch3 := SplitVersion("1.2") 25 require.EqualValues(t, 1, major3) 26 require.EqualValues(t, 2, minor3) 27 require.EqualValues(t, 0, patch3) 28 29 major4, minor4, patch4 := SplitVersion("1") 30 require.EqualValues(t, 1, major4) 31 require.EqualValues(t, 0, minor4) 32 require.EqualValues(t, 0, patch4) 33 34 major5, minor5, patch5 := SplitVersion("1.2.3.junkgoeswhere") 35 require.EqualValues(t, 1, major5) 36 require.EqualValues(t, 2, minor5) 37 require.EqualValues(t, 3, patch5) 38 } 39 40 func TestGetPreviousVersion(t *testing.T) { 41 require.Equal(t, "1.2.0", GetPreviousVersion("1.3.0")) 42 require.Equal(t, "1.1.0", GetPreviousVersion("1.2.1")) 43 require.Equal(t, "1.0.0", GetPreviousVersion("1.1.0")) 44 require.Equal(t, "0.7.0", GetPreviousVersion("1.0.0")) 45 require.Equal(t, "0.6.0", GetPreviousVersion("0.7.1")) 46 require.Equal(t, "", GetPreviousVersion("0.5.0")) 47 } 48 49 func TestIsCurrentVersion(t *testing.T) { 50 major, minor, patch := SplitVersion(CurrentVersion) 51 52 require.True(t, IsCurrentVersion(CurrentVersion)) 53 require.True(t, IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor, patch+100))) 54 require.False(t, IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major, minor+1, patch))) 55 require.False(t, IsCurrentVersion(fmt.Sprintf("%v.%v.%v", major+1, minor, patch))) 56 } 57 58 func TestIsPreviousVersionsSupported(t *testing.T) { 59 require.True(t, IsPreviousVersionsSupported(versionsWithoutHotFixes[0])) 60 require.True(t, IsPreviousVersionsSupported(versionsWithoutHotFixes[1])) 61 require.True(t, IsPreviousVersionsSupported(versionsWithoutHotFixes[2])) 62 require.False(t, IsPreviousVersionsSupported(versionsWithoutHotFixes[4])) 63 require.False(t, IsPreviousVersionsSupported(versionsWithoutHotFixes[5])) 64 }